Ejemplo n.º 1
0
        private void Add(SerialSession session)
        {
            // Build the filter chain of this session.
            session.Service.FilterChainBuilder.BuildFilterChain(session.FilterChain);

            // Propagate the SESSION_CREATED event up to the chain
            IoServiceSupport serviceSupport = session.Service as IoServiceSupport;

            if (serviceSupport != null)
            {
                serviceSupport.FireSessionCreated(session);
            }

            session.Start();
        }
Ejemplo n.º 2
0
        private IoSession NewSessionWithoutLock(EndPoint remoteEP, SocketContext ctx)
        {
            IoSession session;

            lock (_sessionRecycler)
            {
                session = _sessionRecycler.Recycle(remoteEP);

                if (session != null)
                {
                    return(session);
                }

                // If a new session needs to be created.
                session = new AsyncDatagramSession(this, this, ctx, remoteEP, ReuseBuffer);
                _sessionRecycler.Put(session);
            }

            InitSession <IoFuture>(session, null, null);

            try
            {
                FilterChainBuilder.BuildFilterChain(session.FilterChain);

                IoServiceSupport serviceSupport = session.Service as IoServiceSupport;
                if (serviceSupport != null)
                {
                    serviceSupport.FireSessionCreated(session);
                }
            }
            catch (Exception ex)
            {
                ExceptionMonitor.Instance.ExceptionCaught(ex);
            }

            return(session);
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        protected override IConnectFuture Connect0(EndPoint remoteEP, EndPoint localEP, Action <IoSession, IConnectFuture> sessionInitializer)
        {
            LoopbackPipe entry;

            if (!LoopbackAcceptor.BoundHandlers.TryGetValue(remoteEP, out entry))
            {
                return(DefaultConnectFuture.NewFailedFuture(new IOException("Endpoint unavailable: " + remoteEP)));
            }

            DefaultConnectFuture future = new DefaultConnectFuture();

            // Assign the local end point dynamically,
            LoopbackEndPoint actualLocalEP;

            try
            {
                actualLocalEP = NextLocalEP();
            }
            catch (IOException e)
            {
                return(DefaultConnectFuture.NewFailedFuture(e));
            }

            LoopbackSession localSession = new LoopbackSession(this, actualLocalEP, Handler, entry);

            InitSession(localSession, future, sessionInitializer);

            // and reclaim the local end point when the connection is closed.
            localSession.CloseFuture.Complete += ReclaimLocalEP;

            // initialize connector session
            try
            {
                IoFilterChain filterChain = localSession.FilterChain;
                this.FilterChainBuilder.BuildFilterChain(filterChain);

                // The following sentences don't throw any exceptions.
                IoServiceSupport serviceSupport = this as IoServiceSupport;
                if (serviceSupport != null)
                {
                    serviceSupport.FireSessionCreated(localSession);
                }
            }
            catch (Exception ex)
            {
                future.Exception = ex;
                return(future);
            }

            // initialize acceptor session
            LoopbackSession remoteSession = localSession.RemoteSession;

            ((LoopbackAcceptor)remoteSession.Service).DoFinishSessionInitialization(remoteSession, null);
            try
            {
                IoFilterChain filterChain = remoteSession.FilterChain;
                entry.Acceptor.FilterChainBuilder.BuildFilterChain(filterChain);

                // The following sentences don't throw any exceptions.
                IoServiceSupport serviceSupport = entry.Acceptor as IoServiceSupport;
                if (serviceSupport != null)
                {
                    serviceSupport.FireSessionCreated(remoteSession);
                }
            }
            catch (Exception ex)
            {
                ExceptionMonitor.Instance.ExceptionCaught(ex);
                remoteSession.Close(true);
            }

            // Start chains, and then allow and messages read/written to be processed. This is to ensure that
            // sessionOpened gets received before a messageReceived
            ((LoopbackFilterChain)localSession.FilterChain).Start();
            ((LoopbackFilterChain)remoteSession.FilterChain).Start();

            return(future);
        }