Beispiel #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);
        }
Beispiel #2
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();
        }