Beispiel #1
0
 private void CloseSessionForMaxConnectionReach(Socket client)
 {
     AppServer.AsyncRun(client.SafeClose);
     if (AppServer.Logger.IsErrorEnabled)
     {
         AppServer.Logger.ErrorFormat("Max connection number {0} was reached!", AppServer.Config.MaxConnectionNumber);
     }
 }
Beispiel #2
0
        private IAppSession ProcessNewClient(Socket client, SslProtocols security)
        {
            //Get the socket for the accepted client connection and put it into the
            //ReadEventArg object user token
            SocketAsyncEventArgsProxy socketEventArgsProxy;

            if (!m_ReadWritePool.TryPop(out socketEventArgsProxy))
            {
                AppServer.AsyncRun(client.SafeClose);
                if (AppServer.Logger.IsErrorEnabled)
                {
                    AppServer.Logger.ErrorFormat("Max connection number {0} was reached!", AppServer.Config.MaxConnectionNumber);
                }

                return(null);
            }

            ISocketSession socketSession;

            if (security == SslProtocols.None)
            {
                socketSession = new AsyncSocketSession(client, socketEventArgsProxy);
            }
            else
            {
                socketSession = new AsyncStreamSocketSession(client, security, socketEventArgsProxy);
            }

            var session = CreateSession(client, socketSession);

            if (session == null)
            {
                socketEventArgsProxy.Reset();
                this.m_ReadWritePool.Push(socketEventArgsProxy);
                AppServer.AsyncRun(client.SafeClose);
                return(null);
            }

            socketSession.Closed += SessionClosed;

            var negotiateSession = socketSession as INegotiateSocketSession;

            if (negotiateSession == null)
            {
                if (RegisterSession(session))
                {
                    AppServer.AsyncRun(() => socketSession.Start());
                }

                return(session);
            }

            negotiateSession.NegotiateCompleted += OnSocketSessionNegotiateCompleted;
            negotiateSession.Negotiate();

            return(null);
        }
Beispiel #3
0
        private IAppSession ProcessNewClient(Socket socket, SslProtocols security)
        {
            if (!_readWritePool.TryPop(out SocketAsyncEventArgsProxy result))
            {
                AppServer.AsyncRun(() => socket.Shutdown(SocketShutdown.Both));
                return(null);
            }

            result.SocketEventArgs.Completed += SocketEventArgs_Completed;

            ISocketSession socketSession = new AsyncSocketSession(socket, result);

            socketSession.InitializeSendingQueue(this.SendingQueuePool);

            socketSession.Initialize(null);

            socketSession.Start();


            //var session = CreateSession(socket, socketSession);


            //if (session == null)
            //{
            //    result.Reset();
            //    this._readWritePool.Push(result);
            //    AppServer.AsyncRun(() => socket.Shutdown(SocketShutdown.Both));
            //    return null;
            //}

            socketSession.Closed += SessionClosed;

            //var negotiateSession = socketSession as INegotiateSocketSession;

            //if (negotiateSession == null)
            //{
            //    if (RegisterSession(session))
            //    {
            //        AppServer.AsyncRun(() => socketSession.Start());
            //    }

            //    return session;
            //}

            //negotiateSession.NegotiateCompleted += OnSocketSessionNegotiateCompleted;
            //negotiateSession.Negotiate();

            return(null);
        }
Beispiel #4
0
        private void OnSocketSessionNegotiateCompleted(object sender, EventArgs e)
        {
            var socketSession    = sender as ISocketSession;
            var negotiateSession = socketSession as INegotiateSocketSession;

            if (!negotiateSession.Result)
            {
                socketSession.Close(CloseReason.SocketError);
                return;
            }

            if (RegisterSession(negotiateSession.AppSession))
            {
                AppServer.AsyncRun(() => socketSession.Start());
            }
        }
Beispiel #5
0
        protected override void OnNewClientAccepted(ISocketListener listener, Socket client, object state)
        {
            if (IsStopped)
            {
                return;
            }

            //Get the socket for the accepted client connection and put it into the
            //ReadEventArg object user token
            SocketAsyncEventArgsProxy socketEventArgsProxy;

            if (!m_ReadWritePool.TryPop(out socketEventArgsProxy))
            {
                AppServer.AsyncRun(client.SafeClose);
                if (AppServer.Logger.IsErrorEnabled)
                {
                    AppServer.Logger.ErrorFormat("Max connection number {0} was reached!", AppServer.Config.MaxConnectionNumber);
                }
                return;
            }

            ISocketSession session;

            var security = listener.Info.Security;

            if (security == SslProtocols.None)
            {
                session = RegisterSession(client, new AsyncSocketSession(client, socketEventArgsProxy));
            }
            else
            {
                session = RegisterSession(client, new AsyncStreamSocketSession(client, security, socketEventArgsProxy));
            }

            if (session == null)
            {
                socketEventArgsProxy.Reset();
                this.m_ReadWritePool.Push(socketEventArgsProxy);
                AppServer.AsyncRun(client.SafeClose);
                return;
            }

            session.Closed += SessionClosed;
            AppServer.AsyncRun(() => session.Start());
        }
Beispiel #6
0
        private IAppSession ProcessNewClient(Socket client, SslProtocols security)
        {
            if (!IncreaseConnections(client))
            {
                return(null);
            }

            ISocketSession socketSession;

            if (security == SslProtocols.None)
            {
                socketSession = new AsyncSocketSession(client, SaePool);
            }
            else
            {
                socketSession = new AsyncStreamSocketSession(client, security, BufferStatePool);
            }

            var session = CreateSession(client, socketSession);

            if (session == null)
            {
                AppServer.AsyncRun(client.SafeClose);
                return(null);
            }

            socketSession.Closed += SessionClosed;

            var negotiateSession = socketSession as INegotiateSocketSession;

            if (negotiateSession == null)
            {
                if (RegisterSession(session))
                {
                    AppServer.AsyncRun(() => socketSession.Start());
                }

                return(session);
            }

            negotiateSession.NegotiateCompleted += OnSocketSessionNegotiateCompleted;
            negotiateSession.Negotiate();

            return(null);
        }