示例#1
0
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(ChannelDemuxerFilter filter) where TChannel : class, IChannel
        {
            LayeredChannelListener <TChannel> listener = this.CreateListener <TChannel>(filter);

            listener.InnerChannelListener = this.innerListener;
            return(listener);
        }
示例#2
0
 public OpenAsyncResult(DatagramChannelDemuxer <TInnerChannel, TInnerItem> channelDemuxer, ChannelDemuxerFilter filter, IChannelListener listener, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.channelDemuxer = channelDemuxer;
     this.filter         = filter;
     this.listener       = listener;
     this.timeoutHelper  = new TimeoutHelper(timeout);
     if (this.channelDemuxer.openSemaphore.EnterAsync(this.timeoutHelper.RemainingTime(), DatagramChannelDemuxer <TInnerChannel, TInnerItem> .OpenAsyncResult.waitOverCallback, this))
     {
         bool flag  = false;
         bool flag2 = false;
         try
         {
             flag2 = this.OnWaitOver();
             flag  = true;
         }
         finally
         {
             if (!flag)
             {
                 this.Cleanup();
             }
         }
         if (flag2)
         {
             this.Cleanup();
             base.Complete(true);
         }
     }
 }
示例#3
0
        public void OnOuterListenerOpen(ChannelDemuxerFilter filter, IChannelListener listener, TimeSpan timeout)
        {
            TimeoutHelper helper = new TimeoutHelper(timeout);

            this.openSemaphore.Enter(helper.RemainingTime());
            try
            {
                if (this.ShouldStartAccepting(filter, listener))
                {
                    try
                    {
                        this.innerListener.Open(helper.RemainingTime());
                        this.StartAccepting(true);
                        lock (this.ThisLock)
                        {
                            if (this.abortOngoingOpen)
                            {
                                this.innerListener.Abort();
                            }
                        }
                        return;
                    }
                    catch (Exception exception)
                    {
                        this.pendingExceptionOnOpen = exception;
                        throw;
                    }
                }
                this.ThrowPendingOpenExceptionIfAny();
            }
            finally
            {
                this.openSemaphore.Exit();
            }
        }
示例#4
0
 public void OnOuterListenerAbort(ChannelDemuxerFilter filter)
 {
     if (this.ShouldCloseInnerListener(filter, true))
     {
         this.innerListener.Abort();
     }
 }
示例#5
0
 public override IChannelListener <TChannel> BuildChannelListener <TChannel>(ChannelDemuxerFilter filter) where TChannel : class, IChannel
 {
     return(new InputQueueChannelListener <TChannel>(filter, this)
     {
         InnerChannelListener = this.innerListener
     });
 }
示例#6
0
        internal InternalDuplexChannelFactory(InternalDuplexBindingElement bindingElement, BindingContext context, InputChannelDemuxer channelDemuxer, IChannelFactory <IOutputChannel> innerChannelFactory, LocalAddressProvider localAddressProvider) : base(context.Binding, innerChannelFactory)
        {
            this.channelDemuxer      = channelDemuxer;
            this.innerChannelFactory = innerChannelFactory;
            ChannelDemuxerFilter filter = new ChannelDemuxerFilter(new MatchNoneMessageFilter(), -2147483648);

            this.innerChannelListener = this.channelDemuxer.BuildChannelListener <IInputChannel>(filter);
            this.localAddressProvider = localAddressProvider;
            this.providesCorrelation  = bindingElement.ProvidesCorrelation;
        }
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context) where TChannel : class, IChannel
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            ChannelDemuxerFilter filter = context.BindingParameters.Remove <ChannelDemuxerFilter>();

            this.SubstituteCachedBindingContextParametersIfNeeded(context);
            if (filter == null)
            {
                return(this.demuxer.BuildChannelListener <TChannel>(context));
            }
            return(this.demuxer.BuildChannelListener <TChannel>(context, filter));
        }
示例#8
0
 private bool ShouldOpenInnerListener(ChannelDemuxerFilter filter, IChannelListener listener)
 {
     lock (this.ThisLock)
     {
         if ((listener.State == CommunicationState.Closed) || (listener.State == CommunicationState.Closing))
         {
             return(false);
         }
         this.filterTable.Add(filter.Filter, listener, filter.Priority);
         if (++this.openCount == 1)
         {
             this.abortOngoingOpen = false;
             return(true);
         }
     }
     return(false);
 }
示例#9
0
 private bool ShouldCloseInnerListener(ChannelDemuxerFilter filter, bool aborted)
 {
     lock (this.ThisLock)
     {
         if (this.filterTable.ContainsKey(filter.Filter))
         {
             this.filterTable.Remove(filter.Filter);
             if (--this.openCount == 0)
             {
                 if (aborted)
                 {
                     this.abortOngoingOpen = true;
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
示例#10
0
 public void OnOuterListenerClose(ChannelDemuxerFilter filter, TimeSpan timeout)
 {
     if (this.ShouldCloseInnerListener(filter, false))
     {
         bool flag = false;
         try
         {
             this.innerListener.Close(timeout);
             flag = true;
         }
         finally
         {
             if (!flag)
             {
                 this.innerListener.Abort();
             }
         }
     }
 }
示例#11
0
        public IAsyncResult OnBeginOuterListenerClose(ChannelDemuxerFilter filter, TimeSpan timeout, AsyncCallback callback, object state)
        {
            bool flag = false;

            lock (this.ThisLock)
            {
                if (this.filterTable.ContainsKey(filter.Filter))
                {
                    this.filterTable.Remove(filter.Filter);
                    if (--this.openCount == 0)
                    {
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                return(new CompletedAsyncResult(callback, state));
            }
            return(new CloseAsyncResult <TInnerChannel, TInnerItem>((DatagramChannelDemuxer <TInnerChannel, TInnerItem>) this, timeout, callback, state));
        }
示例#12
0
        public void OnOuterListenerAbort(ChannelDemuxerFilter filter)
        {
            bool flag = false;

            lock (this.ThisLock)
            {
                if (this.filterTable.ContainsKey(filter.Filter))
                {
                    this.filterTable.Remove(filter.Filter);
                    if (--this.openCount == 0)
                    {
                        flag = true;
                        this.abortOngoingOpen = true;
                    }
                }
            }
            if (flag)
            {
                this.AbortState();
            }
        }
示例#13
0
 public IAsyncResult OnBeginOuterListenerClose(ChannelDemuxerFilter filter, TimeSpan timeout, AsyncCallback callback, object state)
 {
     if (this.ShouldCloseInnerListener(filter, false))
     {
         bool flag = false;
         try
         {
             IAsyncResult result = this.innerListener.BeginClose(timeout, callback, state);
             flag = true;
             return(result);
         }
         finally
         {
             if (!flag)
             {
                 this.innerListener.Abort();
             }
         }
     }
     return(new CompletedAsyncResult(callback, state));
 }
示例#14
0
        public IDuplexChannel CreateChannel(EndpointAddress remoteAddress, Uri via, EndpointAddress localAddress, MessageFilter filter, int priority, bool usesUniqueHeader)
        {
            ChannelDemuxerFilter             demuxFilter        = new ChannelDemuxerFilter(new AndMessageFilter(new EndpointAddressMessageFilter(localAddress, true), filter), priority);
            IDuplexChannel                   newChannel         = null;
            IOutputChannel                   innerOutputChannel = null;
            IChannelListener <IInputChannel> innerInputListener = null;
            IInputChannel innerInputChannel = null;

            try
            {
                innerOutputChannel = this.innerChannelFactory.CreateChannel(remoteAddress, via);
                innerInputListener = this.channelDemuxer.BuildChannelListener <IInputChannel>(demuxFilter);
                innerInputListener.Open();
                innerInputChannel = innerInputListener.AcceptChannel();
                newChannel        = new ClientCompositeDuplexChannel(this, innerInputChannel, innerInputListener, localAddress, innerOutputChannel, usesUniqueHeader);
            }
            finally
            {
                if (newChannel == null) // need to cleanup
                {
                    if (innerOutputChannel != null)
                    {
                        innerOutputChannel.Close();
                    }

                    if (innerInputListener != null)
                    {
                        innerInputListener.Close();
                    }

                    if (innerInputChannel != null)
                    {
                        innerInputChannel.Close();
                    }
                }
            }

            return(newChannel);
        }
示例#15
0
        public void OnOuterListenerOpen(ChannelDemuxerFilter filter, IChannelListener listener, TimeSpan timeout)
        {
            TimeoutHelper helper = new TimeoutHelper(timeout);

            this.openSemaphore.Enter(helper.RemainingTime());
            try
            {
                if (this.ShouldOpenInnerListener(filter, listener))
                {
                    try
                    {
                        this.innerListener.Open(helper.RemainingTime());
                        this.innerChannel = this.innerListener.AcceptChannel(helper.RemainingTime());
                        this.innerChannel.Open(helper.RemainingTime());
                        lock (this.ThisLock)
                        {
                            if (this.abortOngoingOpen)
                            {
                                this.AbortState();
                                return;
                            }
                        }
                        ActionItem.Schedule(DatagramChannelDemuxer <TInnerChannel, TInnerItem> .startReceivingStatic, this);
                        return;
                    }
                    catch (Exception exception)
                    {
                        this.pendingInnerListenerOpenException = exception;
                        throw;
                    }
                }
                this.ThrowPendingOpenExceptionIfAny();
            }
            finally
            {
                this.openSemaphore.Exit();
            }
        }
示例#16
0
        public void OnOuterListenerClose(ChannelDemuxerFilter filter, TimeSpan timeout)
        {
            bool          flag   = false;
            TimeoutHelper helper = new TimeoutHelper(timeout);

            lock (this.ThisLock)
            {
                if (this.filterTable.ContainsKey(filter.Filter))
                {
                    this.filterTable.Remove(filter.Filter);
                    if (--this.openCount == 0)
                    {
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                bool flag2 = false;
                try
                {
                    if (this.innerChannel != null)
                    {
                        this.innerChannel.Close(helper.RemainingTime());
                    }
                    this.innerListener.Close(helper.RemainingTime());
                    flag2 = true;
                }
                finally
                {
                    if (!flag2)
                    {
                        this.AbortState();
                    }
                }
            }
        }
        protected override LayeredChannelListener <TChannel> CreateListener <TChannel>(ChannelDemuxerFilter filter) where TChannel : class, IChannel
        {
            SingletonChannelListener <IReplyChannel, ReplyChannel, RequestContext> listener2;

            if (typeof(TChannel) == typeof(IInputChannel))
            {
                SingletonChannelListener <IInputChannel, InputChannel, Message> listener;
                return((LayeredChannelListener <TChannel>) new SingletonChannelListener <IInputChannel, InputChannel, Message>(filter, this)
                {
                    Acceptor = new InputChannelAcceptor(listener)
                });
            }
            if (typeof(TChannel) != typeof(IReplyChannel))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
            }
            return((LayeredChannelListener <TChannel>) new SingletonChannelListener <IReplyChannel, ReplyChannel, RequestContext>(filter, this)
            {
                Acceptor = new ReplyChannelAcceptor(listener2)
            });
        }
 public InputQueueChannelListener(ChannelDemuxerFilter filter, IChannelDemuxer channelDemuxer) : base(true)
 {
     this.filter         = filter;
     this.channelDemuxer = channelDemuxer;
     base.Acceptor       = new InputQueueChannelAcceptor <TChannel>(this);
 }
 public SingletonChannelListener(ChannelDemuxerFilter filter, IChannelDemuxer channelDemuxer) : base(true)
 {
     this.filter         = filter;
     this.channelDemuxer = channelDemuxer;
 }
示例#20
0
 protected abstract LayeredChannelListener <TChannel> CreateListener <TChannel>(ChannelDemuxerFilter filter) where TChannel : class, IChannel;
示例#21
0
 public IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context, ChannelDemuxerFilter filter) where TChannel : class, IChannel
 {
     return(this.GetTypedDemuxer(typeof(TChannel), context).BuildChannelListener <TChannel>(filter));
 }
 public abstract IChannelListener <TChannel> BuildChannelListener <TChannel>(ChannelDemuxerFilter filter) where TChannel : class, IChannel;
示例#23
0
 public IAsyncResult OnBeginOuterListenerOpen(ChannelDemuxerFilter filter, IChannelListener listener, TimeSpan timeout, AsyncCallback callback, object state)
 {
     return(new OpenAsyncResult <TInnerChannel, TInnerItem>((DatagramChannelDemuxer <TInnerChannel, TInnerItem>) this, filter, listener, timeout, callback, state));
 }
示例#24
0
        protected override LayeredChannelListener <IInputChannel> CreateListener <IInputChannel>(ChannelDemuxerFilter filter) where IInputChannel : class, IChannel
        {
            SingletonChannelListener <IInputChannel, InputChannel, Message> listener;

            return(new SingletonChannelListener <IInputChannel, InputChannel, Message>(filter, this)
            {
                Acceptor = (IChannelAcceptor <IInputChannel>) new InputChannelAcceptor(listener)
            });
        }