Exemple #1
0
        void ProcessAccept(SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                try
                {
                    //Microsoft needs to fix this to not throw when null
                    if (e.AcceptSocket.RemoteEndPoint == null)
                    {
                        throw new Exception("RemoteEndPoint IS NULL ?");
                    }
                }
                catch (SocketException)
                {
                    goto EndAccept;
                }

                var conn = this.OnNewConnection(this, e.AcceptSocket);
                conn.Socket = e.AcceptSocket;

                SocketAsyncEventArgs readEventArgs = m_readPool.Pop();
                readEventArgs.UserToken = conn;

                Connected[conn.conId] = conn;

                conn.OnConnect();

                if (!e.AcceptSocket.ReceiveAsync(readEventArgs))
                {
                    ProcessReceive(readEventArgs);
                }
            }

EndAccept:
            e.AcceptSocket = null;
            this.StartAccept(e);
        }
Exemple #2
0
        void ProcessAccept(SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                try
                {
                    if (e.AcceptSocket.RemoteEndPoint == null)
                    {
                        throw new Exception("RemoteEndPoint IS NULL ?");
                    }
                }
                catch (SocketException)
                {
                    //Console.WriteLine("RemoteEndPoint failed with: " + se.Message);
                    goto EndAccept;
                }

                var conn = this.OnNewConnection(this, e.AcceptSocket);
                conn.Socket = e.AcceptSocket;

                SocketAsyncEventArgs readEventArgs = m_readPool.Pop();
                readEventArgs.UserToken = conn;

                Connected[conn.conId] = conn;

                conn.OnConnect();

                if (!e.AcceptSocket.ReceiveAsync(readEventArgs))
                {
                    ProcessReceive(readEventArgs);
                }
            }

EndAccept:
            e.AcceptSocket = null;
            this.StartAccept(e);
        }