Exemple #1
0
        internal ISingletonChannelListener OnGetSingletonMessageHandler(ServerSingletonPreambleConnectionReader serverSingletonPreambleReader)
        {
            Uri via = serverSingletonPreambleReader.Via;
            TChannelListener channelListener = GetChannelListener(via);

            if (channelListener != null)
            {
                if (channelListener is IChannelListener <IReplyChannel> )
                {
                    channelListener.RaiseMessageReceived();
                    return((ISingletonChannelListener)channelListener);
                }
                else
                {
                    serverSingletonPreambleReader.SendFault(FramingEncodingString.UnsupportedModeFault);
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ProtocolException(SR.Format(SR.FramingModeNotSupported, FramingMode.Singleton)));
                }
            }
            else
            {
                serverSingletonPreambleReader.SendFault(FramingEncodingString.EndpointNotFoundFault);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new EndpointNotFoundException(SR.Format(SR.EndpointNotFound, via)));
            }
        }
Exemple #2
0
        void OnSingletonConnection(IConnection connection, Action connectionDequeuedCallback,
                                   long streamPosition, int offset, int size, TimeSpan timeout)
        {
            if (onSingletonPreambleKnown == null)
            {
                onSingletonPreambleKnown = OnSingletonPreambleKnown;
            }
            ServerSingletonPreambleConnectionReader singletonPreambleReader =
                new ServerSingletonPreambleConnectionReader(connection, connectionDequeuedCallback, streamPosition, offset, size,
                                                            transportSettingsCallback, onConnectionClosed, onSingletonPreambleKnown);

            lock (ThisLock)
            {
                if (isDisposed)
                {
                    singletonPreambleReader.Dispose();
                    return;
                }

                connectionReaders.Add(singletonPreambleReader);
            }
            //TODO: This might block a thread. Work out if it's safe to make this method async void
            //      or make the caller async.
            singletonPreambleReader.StartReadingAsync(viaDelegate, timeout).GetAwaiter().GetResult();
        }
Exemple #3
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;
 }
Exemple #4
0
        async Task CompleteSingletonPreambleAsync(ServerSingletonPreambleConnectionReader serverSingletonPreambleReader, ISingletonChannelListener singletonChannelListener)
        {
            var         timeoutHelper      = new TimeoutHelper(singletonChannelListener.ReceiveTimeout);
            IConnection upgradedConnection = await serverSingletonPreambleReader.CompletePreambleAsync(singletonChannelListener.ReceiveTimeout);

            ServerSingletonConnectionReader singletonReader = new ServerSingletonConnectionReader(serverSingletonPreambleReader, upgradedConnection, this);

            //singletonReader doesn't have async version of ReceiveRequest, so just call the sync method for now.
            RequestContext requestContext = await singletonReader.ReceiveRequestAsync(timeoutHelper.GetCancellationToken());

            singletonChannelListener.ReceiveRequest(requestContext, serverSingletonPreambleReader.ConnectionDequeuedCallback, true);
        }
Exemple #5
0
        void OnSingletonPreambleKnown(ServerSingletonPreambleConnectionReader serverSingletonPreambleReader)
        {
            lock (ThisLock)
            {
                if (isDisposed)
                {
                    return;
                }

                connectionReaders.Remove(serverSingletonPreambleReader);
            }

            ISingletonChannelListener singletonChannelListener = singletonPreambleCallback(serverSingletonPreambleReader);

            Fx.Assert(singletonChannelListener != null,
                      "singletonPreambleCallback must return a listener or send a Fault/throw");

            // transfer ownership of the connection from the preamble reader to the message handler

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            CompleteSingletonPreambleAsync(serverSingletonPreambleReader, singletonChannelListener);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }