Exemplo n.º 1
0
 private void RemoveConnection(RpcTcpServerConnection cnn)
 {
     lock (_syncRoot) {
         if (_connections.ContainsKey(cnn.RemoteUri))
         {
             _connections.Remove(cnn.RemoteUri);
         }
     }
 }
Exemplo n.º 2
0
        void ProcessAccept(SocketAsyncEventArgs e)
        {
            _tracing.InfoFmt("Accept Connection");

            try {
                RpcTcpSocketConnection s    = new RpcTcpSocketConnection(RpcConnectionDirection.Server);
                RpcTcpServerConnection conn = new RpcTcpServerConnection(this, s);

                conn.TransactionCreated += new Action <RpcConnection, RpcServerTransaction>(
                    (cnn, tx) => {
                    OnTransactionCreated(tx);
                }
                    );

                conn.Disconnected += new Action <RpcConnection>(
                    (cnn) => {
                    RemoveConnection((RpcTcpServerConnection)cnn);
                }
                    );

                //
                // 把事件都挂全了的,再beginrecieve
                s.Accept(e);

                // 按原来的逻辑此时conn.RemoteUri = null;
                lock (_syncRoot) {
                    _connections.Add(conn.RemoteUri, conn);
                }
                _tracing.InfoFmt("Connection Created from {0}", conn.RemoteUri);
                OnConnectionCreated(conn);
            } catch (Exception ex) {
                try {
                    e.AcceptSocket.Close();
                } catch (Exception ex2) {
                    _tracing.Error(ex2, "AcceptSocket.Close() Failed");
                }
                _tracing.Error(ex, "ProcessConnect Failed");
            } finally {
                e.AcceptSocket = null;
                BeginAccept();
            }
        }