示例#1
0
        static void AcceptCallback(IAsyncResult result)
        {
            if (Server.shuttingDown)
            {
                return;
            }
            TcpListen listen = (TcpListen)result.AsyncState;
            TcpSocket s      = null;

            try {
                Socket raw = listen.socket.EndAccept(result);
                s = new TcpSocket(raw);

                Logger.Log(LogType.UserActivity, s.IP + " connected to the server.");
                s.Init();
            } catch (Exception ex) {
                if (!(ex is SocketException))
                {
                    Logger.LogError(ex);
                }
                if (s != null)
                {
                    s.Close();
                }
            }
            listen.AcceptNextAsync();
        }
示例#2
0
        static void AcceptCallback(IAsyncResult result)
        {
            if (Server.shuttingDown)
            {
                return;
            }
            TcpListen listen = (TcpListen)result.AsyncState;
            TcpSocket s      = null;

            try {
                Socket raw    = listen.socket.EndAccept(result);
                bool   cancel = false;

                OnConnectionReceivedEvent.Call(raw, ref cancel);
                if (cancel)
                {
                    // intentionally non-clean connection close
                    try { raw.Close(); } catch { }
                }
                else
                {
                    s = new TcpSocket(raw);
                    Logger.Log(LogType.UserActivity, s.IP + " connected to the server.");
                    s.Init();
                }
            } catch (Exception ex) {
                if (!(ex is SocketException))
                {
                    Logger.LogError(ex);
                }
                if (s != null)
                {
                    s.Close();
                }
            }
            listen.AcceptNextAsync();
        }