NamedPipeChannelListener.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / NamedPipeChannelListener.cs / 1 / NamedPipeChannelListener.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.ServiceModel.Channels 
{
    using System.Collections.Generic; 
    using System.Collections.ObjectModel; 
    using System.Diagnostics;
    using System.IO; 
    using System.Runtime.Serialization;
    using System.Text;
    using System.Threading;
    using System.Security.Principal; 
    using System.ServiceModel;
    using System.ServiceModel.Diagnostics; 
 
    abstract class NamedPipeChannelListener
        : NamedPipeChannelListener, IChannelListener 
        where TChannel : class, IChannel
        where TChannelAcceptor : ChannelAcceptor
    {
        protected NamedPipeChannelListener(NamedPipeTransportBindingElement bindingElement, BindingContext context) 
            : base(bindingElement, context)
        { 
        } 

        protected abstract TChannelAcceptor ChannelAcceptor { get; } 

        protected override void OnOpen(TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); 
            base.OnOpen(timeoutHelper.RemainingTime());
            ChannelAcceptor.Open(timeoutHelper.RemainingTime()); 
        } 

        protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) 
        {
            return new ChainedOpenAsyncResult(timeout, callback, state, base.OnBeginOpen, base.OnEndOpen, ChannelAcceptor);
        }
 
        protected override void OnEndOpen(IAsyncResult result)
        { 
            ChainedOpenAsyncResult.End(result); 
        }
 
        protected override void OnClose(TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            ChannelAcceptor.Close(timeoutHelper.RemainingTime()); 
            base.OnClose(timeoutHelper.RemainingTime());
        } 
 
        protected override void OnAbort()
        { 
            this.ChannelAcceptor.Abort();
            base.OnAbort();
        }
 
        protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state)
        { 
            return new ChainedCloseAsyncResult(timeout, callback, state, base.OnBeginClose, base.OnEndClose, ChannelAcceptor); 
        }
 
        protected override void OnEndClose(IAsyncResult result)
        {
            ChainedCloseAsyncResult.End(result);
        } 

        public TChannel AcceptChannel() 
        { 
            return this.AcceptChannel(this.DefaultReceiveTimeout);
        } 

        public IAsyncResult BeginAcceptChannel(AsyncCallback callback, object state)
        {
            return this.BeginAcceptChannel(this.DefaultReceiveTimeout, callback, state); 
        }
 
        public TChannel AcceptChannel(TimeSpan timeout) 
        {
            base.ThrowIfNotOpened(); 
            return ChannelAcceptor.AcceptChannel(timeout);
        }

        public IAsyncResult BeginAcceptChannel(TimeSpan timeout, AsyncCallback callback, object state) 
        {
            base.ThrowIfNotOpened(); 
            return ChannelAcceptor.BeginAcceptChannel(timeout, callback, state); 
        }
 
        public TChannel EndAcceptChannel(IAsyncResult result)
        {
            base.ThrowPending();
            return ChannelAcceptor.EndAcceptChannel(result); 
        }
 
        protected override bool OnWaitForChannel(TimeSpan timeout) 
        {
            return ChannelAcceptor.WaitForChannel(timeout); 
        }

        protected override IAsyncResult OnBeginWaitForChannel(TimeSpan timeout, AsyncCallback callback, object state)
        { 
            return ChannelAcceptor.BeginWaitForChannel(timeout, callback, state);
        } 
 
        protected override bool OnEndWaitForChannel(IAsyncResult result)
        { 
            return ChannelAcceptor.EndWaitForChannel(result);
        }
    }
 
    class NamedPipeReplyChannelListener
        : NamedPipeChannelListener 
        , ISingletonChannelListener 
    {
        ReplyChannelAcceptor replyAcceptor; 

        public NamedPipeReplyChannelListener(NamedPipeTransportBindingElement bindingElement, BindingContext context)
            : base(bindingElement, context)
        { 
            this.replyAcceptor = new ConnectionOrientedTransportReplyChannelAcceptor(this);
        } 
 
        protected override ReplyChannelAcceptor ChannelAcceptor
        { 
            get { return this.replyAcceptor; }
        }

        TimeSpan ISingletonChannelListener.ReceiveTimeout 
        {
            get { return this.InternalReceiveTimeout; } 
        } 

        void ISingletonChannelListener.ReceiveRequest(RequestContext requestContext, ItemDequeuedCallback callback, bool canDispatchOnThisThread) 
        {
            if (DiagnosticUtility.ShouldTraceVerbose)
            {
                TraceUtility.TraceEvent(TraceEventType.Verbose, MessageReceivedTraceCode, requestContext.RequestMessage); 
            }
            replyAcceptor.Enqueue(requestContext, callback, canDispatchOnThisThread); 
        } 
    }
 
    class NamedPipeDuplexChannelListener
        : NamedPipeChannelListener>
        , ISessionPreambleHandler
    { 
        InputQueueChannelAcceptor duplexAcceptor;
 
        public NamedPipeDuplexChannelListener(NamedPipeTransportBindingElement bindingElement, BindingContext context) 
            : base(bindingElement, context)
        { 
            this.duplexAcceptor = new InputQueueChannelAcceptor(this);
        }

        protected override InputQueueChannelAcceptor ChannelAcceptor 
        {
            get { return this.duplexAcceptor; } 
        } 

        void ISessionPreambleHandler.HandleServerSessionPreamble(ServerSessionPreambleConnectionReader preambleReader, 
            ConnectionDemuxer connectionDemuxer)
        {
            IDuplexSessionChannel channel = preambleReader.CreateDuplexSessionChannel(
                this, new EndpointAddress(this.Uri), ExposeConnectionProperty, connectionDemuxer); 

            duplexAcceptor.EnqueueAndDispatch(channel, preambleReader.ConnectionDequeuedCallback); 
        } 
    }
 
    abstract class NamedPipeChannelListener : ConnectionOrientedTransportChannelListener
    {
        List allowedUsers;
 
        protected NamedPipeChannelListener(NamedPipeTransportBindingElement bindingElement, BindingContext context)
            : base(bindingElement, context) 
        { 
            SetIdleTimeout(bindingElement.ConnectionPoolSettings.IdleTimeout);
            SetMaxPooledConnections(bindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint); 
        }

        static UriPrefixTable transportManagerTable =
            new UriPrefixTable(); 

        public override string Scheme 
        { 
            get { return Uri.UriSchemeNetPipe; }
        } 

        internal List AllowedUsers
        {
            get 
            {
                return allowedUsers; 
            } 
            set
            { 
                lock (ThisLock)
                {
                    ThrowIfDisposedOrImmutable();
                    this.allowedUsers = value; 
                }
            } 
        } 

        internal override TraceCode MessageReceivedTraceCode 
        {
            get { return TraceCode.NamedPipeChannelMessageReceived; }
        }
 
        internal override TraceCode MessageReceiveFailedTraceCode
        { 
            get { return TraceCode.NamedPipeChannelMessageReceiveFailed; } 
        }
 
        internal static UriPrefixTable StaticTransportManagerTable
        {
            get
            { 
                return transportManagerTable;
            } 
        } 

        internal override UriPrefixTable TransportManagerTable 
        {
            get
            {
                return transportManagerTable; 
            }
        } 
 
        internal override ITransportManagerRegistration CreateTransportManagerRegistration(Uri listenUri)
        { 
            return new ExclusiveNamedPipeTransportManager(listenUri, this);
        }

        protected override bool SupportsUpgrade(StreamUpgradeBindingElement upgradeBindingElement) 
        {
            return !(upgradeBindingElement is SslStreamSecurityBindingElement); 
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK