Inheritance: SocketSession, IAsyncSocketSession
Example #1
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);
        }
Example #2
0
        public override void ResetSessionSecurity(IAppSession session, SslProtocols security)
        {
            ISocketSession socketSession;

            if (security == SslProtocols.None)
                socketSession = new AsyncSocketSession(session.SocketSession.Client, SaePool, true);
            else
                socketSession = new AsyncStreamSocketSession(session.SocketSession.Client, security, BufferManager, true);

            socketSession.Initialize(session);
            socketSession.Start();
        }
Example #3
0
        public override void ResetSessionSecurity(IAppSession session, SslProtocols security)
        {
            ISocketSession socketSession;

            var socketAsyncProxy = ((IAsyncSocketSessionBase)session.SocketSession).SocketAsyncProxy;

            if (security == SslProtocols.None)
                socketSession = new AsyncSocketSession(session.SocketSession.Client, socketAsyncProxy, true);
            else
                socketSession = new AsyncStreamSocketSession(session.SocketSession.Client, security, socketAsyncProxy, true);

            socketSession.Initialize(session);
            socketSession.Start();
        }
Example #4
0
        public override void ResetSessionSecurity(IAppSession session, SslProtocols security)
        {
            ISocketSession socketSession;

            if (security == SslProtocols.None)
            {
                socketSession = new AsyncSocketSession(session.SocketSession.Client, SaePool, true);
            }
            else
            {
                socketSession = new AsyncStreamSocketSession(session.SocketSession.Client, security, BufferStatePool, true);
            }

            socketSession.Initialize(session);
            socketSession.Start();
        }
Example #5
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);
        }
Example #6
0
        public override void ResetSessionSecurity(IAppSession session, SslProtocols security)
        {
            ISocketSession socketSession;

            var socketAsyncProxy = ((IAsyncSocketSessionBase)session.SocketSession).SocketAsyncProxy;

            if (security == SslProtocols.None)
            {
                socketSession = new AsyncSocketSession(session.SocketSession.Client, socketAsyncProxy, true);
            }
            else
            {
                socketSession = new AsyncStreamSocketSession(session.SocketSession.Client, security, socketAsyncProxy, true);
            }

            socketSession.Initialize(session);
            socketSession.Start();
        }
        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;
        }
Example #8
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 socketSession;

            var security = listener.Info.Security;

            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;
            }

            socketSession.Closed += SessionClosed;

            var negotiateSession = socketSession as INegotiateSocketSession;

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

                return;
            }

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