Exemplo n.º 1
0
 /// <summary>
 /// Constructor for server-side session.
 /// </summary>
 public LoopbackSession(LoopbackSession remoteSession, LoopbackPipe entry)
     : base(entry.Acceptor)
 {
     Config = new DefaultLoopbackSessionConfig();
     _lock = remoteSession._lock;
     _localEP = remoteSession._remoteEP;
     _remoteEP = remoteSession._localEP;
     _filterChain = new LoopbackFilterChain(this);
     _remoteSession = remoteSession;
     _receivedMessageQueue = new ConcurrentQueue<Object>();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor for server-side session.
 /// </summary>
 public LoopbackSession(LoopbackSession remoteSession, LoopbackPipe entry)
     : base(entry.Acceptor)
 {
     Config                = new DefaultLoopbackSessionConfig();
     _lock                 = remoteSession._lock;
     _localEP              = remoteSession._remoteEP;
     _remoteEP             = remoteSession._localEP;
     _filterChain          = new LoopbackFilterChain(this);
     _remoteSession        = remoteSession;
     _receivedMessageQueue = new ConcurrentQueue <Object>();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor for client-side session.
 /// </summary>
 public LoopbackSession(IoService service, LoopbackEndPoint localEP,
     IoHandler handler, LoopbackPipe remoteEntry)
     : base(service)
 {
     Config = new DefaultLoopbackSessionConfig();
     _lock = new Byte[0];
     _localEP = localEP;
     _remoteEP = remoteEntry.Endpoint;
     _filterChain = new LoopbackFilterChain(this);
     _receivedMessageQueue = new ConcurrentQueue<Object>();
     _remoteSession = new LoopbackSession(this, remoteEntry);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor for client-side session.
 /// </summary>
 public LoopbackSession(IoService service, LoopbackEndPoint localEP,
                        IoHandler handler, LoopbackPipe remoteEntry)
     : base(service)
 {
     Config                = new DefaultLoopbackSessionConfig();
     _lock                 = new Byte[0];
     _localEP              = localEP;
     _remoteEP             = remoteEntry.Endpoint;
     _filterChain          = new LoopbackFilterChain(this);
     _receivedMessageQueue = new ConcurrentQueue <Object>();
     _remoteSession        = new LoopbackSession(this, remoteEntry);
 }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        private void FireEvent(IoEvent e)
        {
            LoopbackSession session = (LoopbackSession)Session;
            Object          data    = e.Parameter;

            switch (e.EventType)
            {
            case IoEventType.MessageReceived:
                if (sessionOpened && (!session.ReadSuspended) && Monitor.TryEnter(session.Lock))
                {
                    try
                    {
                        if (session.ReadSuspended)
                        {
                            session.ReceivedMessageQueue.Enqueue(data);
                        }
                        else
                        {
                            base.FireMessageReceived(data);
                        }
                    }
                    finally
                    {
                        Monitor.Exit(session.Lock);
                    }
                }
                else
                {
                    session.ReceivedMessageQueue.Enqueue(data);
                }
                break;

            case IoEventType.Write:
                base.FireFilterWrite((IWriteRequest)data);
                break;

            case IoEventType.MessageSent:
                base.FireMessageSent((IWriteRequest)data);
                break;

            case IoEventType.ExceptionCaught:
                base.FireExceptionCaught((Exception)data);
                break;

            case IoEventType.SessionCreated:
                Monitor.Enter(session.Lock);
                try
                {
                    base.FireSessionCreated();
                }
                finally
                {
                    Monitor.Exit(session.Lock);
                }
                break;

            case IoEventType.SessionOpened:
                base.FireSessionOpened();
                sessionOpened = true;
                break;

            case IoEventType.SessionIdle:
                base.FireSessionIdle((IdleStatus)data);
                break;

            case IoEventType.SessionClosed:
                FlushPendingDataQueues(session);
                base.FireSessionClosed();
                break;

            case IoEventType.Close:
                base.FireFilterClose();
                break;

            default:
                break;
            }
        }
Exemplo n.º 8
0
 private static void FlushPendingDataQueues(LoopbackSession s)
 {
     s.Processor.UpdateTrafficControl(s);
     s.RemoteSession.Processor.UpdateTrafficControl(s);
 }