Example #1
0
        private static void DisconnectCallback(IAsyncResult IAR)
        {
            StateObject state   = (StateObject)IAR.AsyncState;
            Socket      handler = state.workSocket;
            string      key     = state.key;



            handler.EndDisconnect(IAR);



            handler.Shutdown(SocketShutdown.Both);
            handler.Disconnect(true);
            handler.Close();

            handler.Dispose();



            D2Sockets.Remove(key);
            D2TReceive.Remove(key);
            D2TSend.Remove(key);
            D3BReceive.Remove(key);
            D3BSend.Remove(key);
        }
Example #2
0
        private static void AcceptCallback(IAsyncResult IAR)
        {
            Socket Server, handler;

            try
            {
                Server  = (Socket)IAR.AsyncState;
                handler = Server.EndAccept(IAR);
            }
            catch (ObjectDisposedException ode)
            {
                ExceptionBuffer.Add(ode);
                return;
            }

            allDone.Set();

            string sKey = TcpAsyncCommon.DefaultUID + ++iAcceptCounter;

            StateObject state = new StateObject();

            state.workSocket = handler;
            state.key        = sKey;

            D2Sockets.Set(sKey, state);
            D2TReceive.Set(sKey, null);
            D2TSend.Set(sKey, null);
            D3BReceive.Set(sKey, new DataBuffer());
            D3BSend.Set(sKey, new DataBuffer());
        }
Example #3
0
        public void Stop(string key)
        {
            StateObject state = D2Sockets.Get(key);

            try
            {
                if (state != null && state.workSocket != null)
                {
                    Socket handler = state.workSocket;
                    handler.Shutdown(SocketShutdown.Both);
                    handler.Disconnect(true);
                    handler.Close();
                    handler.Dispose();
                }
            }
            catch
            {
            }
            finally
            {
                if (D2Sockets != null)
                {
                    D2Sockets.Remove(key);
                }
                if (D2TReceive != null)
                {
                    D2TReceive.Remove(key);
                }
                if (D2TSend != null)
                {
                    D2TSend.Remove(key);
                }
                if (D3BReceive != null)
                {
                    D3BReceive.Remove(key);
                }
                if (D3BSend != null)
                {
                    D3BSend.Remove(key);
                }
            }
        }