예제 #1
0
        public bool ShutdownOne(EndPoint endPoint)
        {
            if (endPoint == null)
            {
                throw new ArgumentNullException();
            }
            if (this.Connections == null || this.Connections.Count == 0)
            {
                return(false);
            }

            lock (this.SyncRoot)
            {
                TcpConnection conn = null;
                if (this.Connections.TryGetValue(endPoint, out conn))
                {
                    a_conn_OnDisconnected(conn);

                    return(true);
                }
                return(false);
            }
        }
예제 #2
0
 void a_conn_OnDataSendCompleted(TcpConnection a_conn, byte[] data)
 {
     if (this.OnDataSendCompleted != null)
         this.OnDataSendCompleted(a_conn, data);
 }
예제 #3
0
 void a_conn_OnConnected(TcpConnection a_conn)
 {
     if (this.OnConnected != null)
         this.OnConnected(a_conn);
 }
예제 #4
0
 void a_conn_OnDisconnected(TcpConnection a_conn)
 {
     Connections.Remove(a_conn.RemoteEndPoint);
     if (this.OnDisconnected != null)
         this.OnDisconnected(a_conn);
     a_conn.CloseConnection();
 }
예제 #5
0
        void e_Completed(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                if (e.AcceptSocket.Connected)
                {
                    var a_conn = new TcpConnection(e.AcceptSocket);

                    if (this.OnConnected != null)
                        a_conn.OnConnected += new Action<TcpConnection>(this.a_conn_OnConnected);

                    if (this.OnDisconnected != null)
                        a_conn.OnDisconnected += new Action<TcpConnection>(this.a_conn_OnDisconnected);

                    if (this.OnDataReceivedCompleted != null)
                        a_conn.OnDataReceivedCompleted += new Action<TcpConnection, byte[]>(this.a_conn_OnDataReceivedCompleted);

                    if (this.OnDataSendCompleted != null)
                        a_conn.OnDataSendCompleted += new Action<TcpConnection, byte[]>(this.a_conn_OnDataSendCompleted);

                    if (this.ReportReceivedProgress != null)
                        a_conn.ReportReceivedProgress += new Action<SocketAsyncEventArgs, AsyncUserToken>(this.a_conn_ReportReceivedProgress);

                    if (this.ReportSendProgress != null)
                        a_conn.ReportSendProgress += new Action<SocketAsyncEventArgs, AsyncUserToken>(this.a_conn_ReportSendProgress);

                    lock (this.SyncRoot)
                    {
                        this.Connections.Add(a_conn.RemoteEndPoint, a_conn);
                        a_conn.StartReceive();
                    }
                }
            }
            catch { }

            e.AcceptSocket = null;
            if (!this.listenSocket.AcceptAsync(e))
                this.e_Completed(null, e);
        }