示例#1
0
        private static void HandleEndTryReceive(IAsyncResult result)
        {
            BufferedReceiveBinder asyncState = (BufferedReceiveBinder)result.AsyncState;
            bool flag = false;

            try
            {
                RequestContext context;
                if (asyncState.channelBinder.EndTryReceive(result, out context))
                {
                    flag = asyncState.inputQueue.EnqueueWithoutDispatch(new RequestContextWrapper(context), null);
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                flag = asyncState.inputQueue.EnqueueWithoutDispatch(exception, null);
            }
            finally
            {
                Interlocked.Exchange(ref asyncState.pendingOperationSemaphore, 0);
                if (flag)
                {
                    asyncState.inputQueue.Dispatch();
                }
            }
        }
        static void HandleEndTryReceive(IAsyncResult result)
        {
            BufferedReceiveBinder binder = (BufferedReceiveBinder)result.AsyncState;

            RequestContext requestContext;
            bool           requiresDispatch = false;

            try
            {
                if (binder.channelBinder.EndTryReceive(result, out requestContext))
                {
                    requiresDispatch = binder.inputQueue.EnqueueWithoutDispatch(new RequestContextWrapper(requestContext), null);
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                requiresDispatch = binder.inputQueue.EnqueueWithoutDispatch(exception, null);
            }
            finally
            {
                Interlocked.Exchange(ref binder.pendingOperationSemaphore, 0);
                if (requiresDispatch)
                {
                    binder.inputQueue.Dispatch();
                }
            }
        }
示例#3
0
        private static void TryReceive(object state)
        {
            BufferedReceiveBinder binder = (BufferedReceiveBinder)state;
            bool flag = false;

            try
            {
                RequestContext context;
                if (binder.channelBinder.TryReceive(TimeSpan.MaxValue, out context))
                {
                    flag = binder.inputQueue.EnqueueWithoutDispatch(new RequestContextWrapper(context), null);
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                flag = binder.inputQueue.EnqueueWithoutDispatch(exception, null);
            }
            finally
            {
                Interlocked.Exchange(ref binder.pendingOperationSemaphore, 0);
                if (flag)
                {
                    binder.inputQueue.Dispatch();
                }
            }
        }
示例#4
0
        internal static void Register(ChannelHandler handler, RequestContext request)
        {
            BufferedReceiveBinder bufferedBinder = handler.Binder as BufferedReceiveBinder;

            Fx.Assert(bufferedBinder != null, "ChannelHandler.Binder is not a BufferedReceiveBinder");

            bufferedBinder.InjectRequest(request);
            handler.Register();
        }
示例#5
0
        internal ChannelHandler(MessageVersion messageVersion, IChannelBinder binder,
                                ListenerHandler listener, SessionIdleManager idleManager)
        {
            ChannelDispatcher channelDispatcher = listener.ChannelDispatcher;

            _messageVersion     = messageVersion;
            _isManualAddressing = channelDispatcher.ManualAddressing;
            Binder    = binder;
            _listener = listener;

            _receiveSynchronously = channelDispatcher.ReceiveSynchronously;
            _sendAsynchronously   = channelDispatcher.SendAsynchronously;
            _duplexBinder         = binder as DuplexChannelBinder;
            _hasSession           = binder.HasSession;
            _isConcurrent         = ConcurrencyBehavior.IsConcurrent(channelDispatcher, _hasSession);

            if (channelDispatcher.MaxPendingReceives > 1)
            {
                throw NotImplemented.ByDesign;
            }

            if (channelDispatcher.BufferedReceiveEnabled)
            {
                Binder = new BufferedReceiveBinder(Binder);
            }

            _receiver    = new ErrorHandlingReceiver(Binder, channelDispatcher);
            _idleManager = idleManager;
            Fx.Assert((_idleManager != null) == (Binder.HasSession && _listener.ChannelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout != TimeSpan.MaxValue), "idle manager is present only when there is a session with a finite receive timeout");

            _requestInfo = new RequestInfo(this);

            if (_listener.State == CommunicationState.Opened)
            {
                _listener.ChannelDispatcher.Channels.IncrementActivityCount();
                _incrementedActivityCountInConstructor = true;
            }
        }