Пример #1
0
        private bool VerifySocket(Socket socket)
        {
            try
            {
                var args = new SocketConnectEventArgs(socket);

                EventSink.InvokeSocketConnect(args);

                return(args.AllowConnection);
            }
            catch (Exception ex)
            {
                UOSocket.TraceException(ex);

                return(false);
            }
        }
Пример #2
0
        private void Release(Socket socket)
        {
            try
            {
                socket.Shutdown(SocketShutdown.Both);
            }
            catch (SocketException ex)
            {
                UOSocket.TraceException(ex);
            }

            try
            {
                socket.Close();
            }
            catch (SocketException ex)
            {
                UOSocket.TraceException(ex);
            }
        }
Пример #3
0
        private void OnAccept(IAsyncResult asyncResult)
        {
            Socket accepted = null;

            try
            {
                accepted = m_Listener.EndAccept(asyncResult);
            }
            catch (SocketException ex)
            {
                UOSocket.TraceException(ex);
            }
            catch (ObjectDisposedException)
            {
                return;
            }

            if (accepted != null)
            {
                if (VerifySocket(accepted))
                {
                    Enqueue(accepted);
                }
                else
                {
                    Release(accepted);
                }
            }

            try
            {
                m_Listener.BeginAccept(m_OnAccept, m_Listener);
            }
            catch (SocketException ex)
            {
                UOSocket.TraceException(ex);
            }
            catch (ObjectDisposedException)
            {
            }
        }