示例#1
0
        private void AcceptTcpClientCallback(IAsyncResult asyncResult)
        {
            lock (_syncRoot)
            {
                // Bail out if we're closing.

                if (State != ProtoHostState.Listening)
                    return;

                try
                {
                    var tcpClient = _listener.EndAcceptTcpClient(asyncResult);
                    HostConnection connection = null;

                    try
                    {
                        connection = new HostConnection(this, tcpClient, _streamManager);

                        _connections.Add(connection, null);

                        connection.Connect();
                    }
                    catch
                    {
                        if (connection != null)
                        {
                            _connections.Remove(connection);

                            connection.Dispose();
                        }

                        tcpClient.Close();

                        throw;
                    }
                }
                catch (Exception ex)
                {
                    Log.Info("Failed to accept TCP client", ex);
                }

                try
                {
                    _listener.BeginAcceptTcpClient(AcceptTcpClientCallback, null);
                }
                catch (Exception ex)
                {
                    Log.Warn("BeginAcceptTcpClient failed", ex);

                    Close();
                }
            }
        }
示例#2
0
        internal void RaiseUnhandledException(HostConnection connection, Exception exception)
        {
            Require.NotNull(connection, "connection");
            Require.NotNull(exception, "exception");

            try
            {
                OnUnhandledException(new UnhandledExceptionEventArgs(exception));
            }
            catch (Exception ex)
            {
                Log.Warn("Exception from UnhandledException event", ex);
            }

            try
            {
                connection.Dispose();
            }
            catch (Exception ex)
            {
                Log.Warn("Disposing connection failed", ex);
            }
        }