Example #1
0
        internal void OnHandleServerSessionPreamble(ServerSessionPreambleConnectionReader serverSessionPreambleReader,
                                                    ConnectionDemuxer connectionDemuxer)
        {
            Uri via = serverSessionPreambleReader.Via;
            TChannelListener channelListener = GetChannelListener(via);

            if (channelListener != null)
            {
                ISessionPreambleHandler sessionPreambleHandler = channelListener as ISessionPreambleHandler;

                if (sessionPreambleHandler != null && channelListener is IChannelListener <IDuplexSessionChannel> )
                {
                    sessionPreambleHandler.HandleServerSessionPreamble(serverSessionPreambleReader, connectionDemuxer);
                }
                else
                {
                    serverSessionPreambleReader.SendFault(FramingEncodingString.UnsupportedModeFault);
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ProtocolException(SR.Format(SR.FramingModeNotSupported, FramingMode.Duplex)));
                }
            }
            else
            {
                serverSessionPreambleReader.SendFault(FramingEncodingString.EndpointNotFoundFault);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new EndpointNotFoundException(SR.Format(SR.DuplexSessionListenerNotFound, via.ToString())));
            }
        }
            protected override void ReturnConnectionIfNecessary(bool abort, CancellationToken token)
            {
                var         timeout         = TimeoutHelper.GetOriginalTimeout(token);
                IConnection localConnection = null;

                if (sessionReader != null)
                {
                    lock (ThisLock)
                    {
                        localConnection = sessionReader.GetRawConnection();
                    }
                }

                if (localConnection != null)
                {
                    if (abort)
                    {
                        localConnection.Abort();
                    }
                    else
                    {
                        connectionDemuxer.ReuseConnection(localConnection, timeout);
                    }
                    connectionDemuxer = null;
                }
            }
Example #3
0
        void ISessionPreambleHandler.HandleServerSessionPreamble(ServerSessionPreambleConnectionReader preambleReader,
                                                                 ConnectionDemuxer connectionDemuxer)
        {
            IDuplexSessionChannel channel = preambleReader.CreateDuplexSessionChannel(
                this, new EndpointAddress(Uri), ExposeConnectionProperty, connectionDemuxer);

            duplexAcceptor.EnqueueAndDispatch(channel, preambleReader.ConnectionDequeuedCallback);
        }
Example #4
0
 public ServerSingletonConnectionReader(ServerSingletonPreambleConnectionReader preambleReader,
                                        IConnection upgradedConnection, ConnectionDemuxer connectionDemuxer)
     : base(upgradedConnection, preambleReader.BufferOffset, preambleReader.BufferSize,
            preambleReader.Security, preambleReader.TransportSettings, preambleReader.Via)
 {
     decoder                = preambleReader.Decoder;
     contentType            = decoder.ContentType;
     this.connectionDemuxer = connectionDemuxer;
     rawConnection          = preambleReader.RawConnection;
     channelBindingToken    = preambleReader.ChannelBinding;
 }
        internal override Task OnOpenAsync()
        {
            SocketConnectionListener socketListener = null;

            if (listenSocket != null)
            {
                socketListener = new SocketConnectionListener(listenSocket, this, false);
                listenSocket   = null;
            }
            else
            {
                int port = registration.ListenUri.Port;
                if (port == -1)
                {
                    port = TcpUri.DefaultPort;
                }

                socketListener = new SocketConnectionListener(new IPEndPoint(ipAddress, port), this, false);
            }

            connectionListener = new BufferedConnectionListener(socketListener, MaxOutputDelay, ConnectionBufferSize);
            connectionDemuxer  = new ConnectionDemuxer(connectionListener,
                                                       MaxPendingAccepts, MaxPendingConnections, ChannelInitializationTimeout,
                                                       IdleTimeout, MaxPooledConnections,
                                                       OnGetTransportFactorySettings,
                                                       OnGetSingletonMessageHandler,
                                                       OnHandleServerSessionPreamble,
                                                       OnDemuxerError);

            bool startedDemuxing = false;

            try
            {
                connectionDemuxer.StartDemuxing();
                startedDemuxing = true;
            }
            finally
            {
                if (!startedDemuxing)
                {
                    connectionDemuxer.Dispose();
                }
            }

            return(Task.CompletedTask);
        }
            public ServerFramingDuplexSessionChannel(ConnectionOrientedTransportChannelListener channelListener, ServerSessionPreambleConnectionReader preambleReader,
                                                     EndpointAddress localAddress, bool exposeConnectionProperty, ConnectionDemuxer connectionDemuxer)
                : base(channelListener, localAddress, preambleReader.Via, exposeConnectionProperty)
            {
                this.channelListener   = channelListener;
                this.connectionDemuxer = connectionDemuxer;
                Connection             = preambleReader.Connection;
                decoder          = preambleReader.Decoder;
                connectionBuffer = preambleReader.connectionBuffer;
                offset           = preambleReader.BufferOffset;
                size             = preambleReader.BufferSize;
                rawConnection    = preambleReader.RawConnection;
                StreamUpgradeProvider upgrade = channelListener.Upgrade;

                if (upgrade != null)
                {
                    channelBindingProvider = upgrade.GetProperty <IStreamUpgradeChannelBindingProvider>();
                    upgradeAcceptor        = upgrade.CreateUpgradeAcceptor();
                }
            }
 public IDuplexSessionChannel CreateDuplexSessionChannel(ConnectionOrientedTransportChannelListener channelListener, EndpointAddress localAddress, bool exposeConnectionProperty, ConnectionDemuxer connectionDemuxer)
 {
     return(new ServerFramingDuplexSessionChannel(channelListener, this, localAddress, exposeConnectionProperty, connectionDemuxer));
 }