public override IList <TransportManager> Select(TransportChannelListener channelListener)
        {
            bool useIPv4 = (this.ListenUri.HostNameType != UriHostNameType.IPv6) && Socket.OSSupportsIPv4;
            bool useIPv6 = (this.ListenUri.HostNameType != UriHostNameType.IPv4) && Socket.OSSupportsIPv6;

            TcpChannelListener tcpListener = (TcpChannelListener)channelListener;

            if (!this.IsCompatible(tcpListener, useIPv4, useIPv6))
            {
                return(null);
            }

            IList <TransportManager> result = new List <TransportManager>();

            if (useIPv4)
            {
                this.ProcessSelection(tcpListener, IPAddress.Any, UriHostNameType.IPv4,
                                      ref this.ipv4TransportManager, result);
            }
            if (useIPv6)
            {
                this.ProcessSelection(tcpListener, IPAddress.IPv6Any, UriHostNameType.IPv6,
                                      ref this.ipv6TransportManager, result);
            }
            return(result);
        }
        bool IsCompatible(TcpChannelListener channelListener, bool useIPv4, bool useIPv6)
        {
            if (channelListener.InheritBaseAddressSettings)
            {
                return(true);
            }

            if (useIPv6)
            {
                if (!channelListener.IsScopeIdCompatible(HostNameComparisonMode, this.ListenUri))
                {
                    return(false);
                }
            }

            return(!channelListener.PortSharingEnabled &&
                   (useIPv4 || useIPv6) &&
                   (this.channelInitializationTimeout == channelListener.ChannelInitializationTimeout) &&
                   (this.idleTimeout == channelListener.IdleTimeout) &&
                   (this.maxPooledConnections == channelListener.MaxPooledConnections) &&
                   (this.connectionBufferSize == channelListener.ConnectionBufferSize) &&
                   (!useIPv6 || (this.teredoEnabled == channelListener.TeredoEnabled)) &&
                   (this.listenBacklog == channelListener.ListenBacklog) &&
                   (this.maxPendingConnections == channelListener.MaxPendingConnections) &&
                   (this.maxOutputDelay == channelListener.MaxOutputDelay) &&
                   (this.maxPendingAccepts == channelListener.MaxPendingAccepts));
        }
コード例 #3
0
        protected void SetUri(Uri baseAddress, string relativeAddress)
        {
            Uri fullUri = baseAddress;

            // Ensure that baseAddress Path does end with a slash if we have a relative address
            if (relativeAddress != string.Empty)
            {
                if (!baseAddress.AbsolutePath.EndsWith("/", StringComparison.Ordinal))
                {
                    UriBuilder uriBuilder = new UriBuilder(baseAddress);
                    TcpChannelListener.FixIpv6Hostname(uriBuilder, baseAddress);
                    uriBuilder.Path = uriBuilder.Path + "/";
                    baseAddress     = uriBuilder.Uri;
                }

                fullUri = new Uri(baseAddress, relativeAddress);

                // now see if we need to update our base address (for cases like relative path = "/foo")
                if (!baseAddress.IsBaseOf(fullUri))
                {
                    baseAddress = fullUri;
                }
            }

            this.baseUri = baseAddress;
            ValidateUri(fullUri);
            this.uri = fullUri;
        }
コード例 #4
0
 private void ProcessSelection(TcpChannelListener channelListener, IPAddress ipAddressAny, UriHostNameType ipHostNameType, ref ExclusiveTcpTransportManager transportManager, IList <TransportManager> result)
 {
     if (transportManager == null)
     {
         transportManager = new ExclusiveTcpTransportManager(this, channelListener, ipAddressAny, ipHostNameType);
     }
     result.Add(transportManager);
 }
コード例 #5
0
        public SharedTcpTransportManager(Uri listenUri, TcpChannelListener channelListener)
        {
            this.HostNameComparisonMode = channelListener.HostNameComparisonMode;
            this.listenUri = listenUri;

            // For port sharing, we apply all of the settings from channel listener to the transport manager.
            this.ApplyListenerSettings(channelListener);
        }
コード例 #6
0
 protected override bool IsCompatible(TcpChannelListener channelListener)
 {
     if ((channelListener.HostedVirtualPath == null) && !channelListener.PortSharingEnabled)
     {
         return(false);
     }
     return(base.IsCompatible(channelListener));
 }
コード例 #7
0
 public ExclusiveTcpTransportManagerRegistration(Uri listenUri, TcpChannelListener channelListener) : base(listenUri, channelListener.HostNameComparisonMode)
 {
     this.connectionBufferSize         = channelListener.ConnectionBufferSize;
     this.channelInitializationTimeout = channelListener.ChannelInitializationTimeout;
     this.teredoEnabled         = channelListener.TeredoEnabled;
     this.listenBacklog         = channelListener.ListenBacklog;
     this.maxOutputDelay        = channelListener.MaxOutputDelay;
     this.maxPendingConnections = channelListener.MaxPendingConnections;
     this.maxPendingAccepts     = channelListener.MaxPendingAccepts;
     this.idleTimeout           = channelListener.IdleTimeout;
     this.maxPooledConnections  = channelListener.MaxPooledConnections;
 }
コード例 #8
0
        static Uri BuildUri(string host, int port, Guid guid)
        {
            UriBuilder uriBuilder = new UriBuilder();

            uriBuilder.Host = host;
            if (port > 0)
            {
                uriBuilder.Port = port;
            }
            uriBuilder.Path   = PeerStrings.KnownServiceUriPrefix + '/' + guid;
            uriBuilder.Scheme = Uri.UriSchemeNetTcp;
            TcpChannelListener.FixIpv6Hostname(uriBuilder, uriBuilder.Uri);
            return(uriBuilder.Uri);
        }
コード例 #9
0
        private static Uri BuildUri(string host, int port, Guid guid)
        {
            UriBuilder uriBuilder = new UriBuilder {
                Host = host
            };

            if (port > 0)
            {
                uriBuilder.Port = port;
            }
            uriBuilder.Path   = "PeerChannelEndpoints" + '/' + guid;
            uriBuilder.Scheme = Uri.UriSchemeNetTcp;
            TcpChannelListener.FixIpv6Hostname(uriBuilder, uriBuilder.Uri);
            return(uriBuilder.Uri);
        }
コード例 #10
0
        public static Uri GetListenUri(Uri baseAddress, string relativeAddress)
        {
            Uri uri = baseAddress;

            if (string.IsNullOrEmpty(relativeAddress))
            {
                return(uri);
            }
            if (!baseAddress.AbsolutePath.EndsWith("/", StringComparison.Ordinal))
            {
                UriBuilder uriBuilder = new UriBuilder(baseAddress);
                TcpChannelListener.FixIpv6Hostname(uriBuilder, baseAddress);
                uriBuilder.Path = uriBuilder.Path + "/";
                baseAddress     = uriBuilder.Uri;
            }
            return(new Uri(baseAddress, relativeAddress));
        }
コード例 #11
0
        public static Uri GetListenUri(Uri baseAddress, string relativeAddress)
        {
            Uri fullUri = baseAddress;

            // Ensure that baseAddress Path does end with a slash if we have a relative address
            if (!String.IsNullOrEmpty(relativeAddress))
            {
                if (!baseAddress.AbsolutePath.EndsWith("/", StringComparison.Ordinal))
                {
                    UriBuilder uriBuilder = new UriBuilder(baseAddress);
                    TcpChannelListener.FixIpv6Hostname(uriBuilder, baseAddress);
                    uriBuilder.Path = uriBuilder.Path + "/";
                    baseAddress     = uriBuilder.Uri;
                }

                fullUri = new Uri(baseAddress, relativeAddress);
            }

            return(fullUri);
        }
コード例 #12
0
 protected void SetUri(System.Uri baseAddress, string relativeAddress)
 {
     System.Uri uri = baseAddress;
     if (relativeAddress != string.Empty)
     {
         if (!baseAddress.AbsolutePath.EndsWith("/", StringComparison.Ordinal))
         {
             UriBuilder uriBuilder = new UriBuilder(baseAddress);
             TcpChannelListener.FixIpv6Hostname(uriBuilder, baseAddress);
             uriBuilder.Path = uriBuilder.Path + "/";
             baseAddress     = uriBuilder.Uri;
         }
         uri = new System.Uri(baseAddress, relativeAddress);
         if (!baseAddress.IsBaseOf(uri))
         {
             baseAddress = uri;
         }
     }
     this.baseUri = baseAddress;
     this.ValidateUri(uri);
     this.uri = uri;
 }
コード例 #13
0
        static Uri AddSegment(Uri baseUri, Uri fullUri)
        {
            Uri result = null;

            if (baseUri.AbsolutePath.Length < fullUri.AbsolutePath.Length)
            {
                UriBuilder builder = new UriBuilder(baseUri);
                TcpChannelListener.FixIpv6Hostname(builder, baseUri);
                if (!builder.Path.EndsWith("/", StringComparison.Ordinal))
                {
                    builder.Path = builder.Path + "/";
                    baseUri      = builder.Uri;
                }
                Uri    relativeUri  = baseUri.MakeRelativeUri(fullUri);
                string relativePath = relativeUri.OriginalString;
                int    slashIndex   = relativePath.IndexOf('/');
                string segment      = (slashIndex == -1) ? relativePath : relativePath.Substring(0, slashIndex);
                builder.Path = builder.Path + segment;
                result       = builder.Uri;
            }
            return(result);
        }
コード例 #14
0
        private static System.Uri AddSegment(System.Uri baseUri, System.Uri fullUri)
        {
            System.Uri uri = null;
            if (baseUri.AbsolutePath.Length >= fullUri.AbsolutePath.Length)
            {
                return(uri);
            }
            UriBuilder uriBuilder = new UriBuilder(baseUri);

            TcpChannelListener.FixIpv6Hostname(uriBuilder, baseUri);
            if (!uriBuilder.Path.EndsWith("/", StringComparison.Ordinal))
            {
                uriBuilder.Path = uriBuilder.Path + "/";
                baseUri         = uriBuilder.Uri;
            }
            string originalString = baseUri.MakeRelativeUri(fullUri).OriginalString;
            int    index          = originalString.IndexOf('/');
            string str2           = (index == -1) ? originalString : originalString.Substring(0, index);

            uriBuilder.Path = uriBuilder.Path + str2;
            return(uriBuilder.Uri);
        }
        public ExclusiveTcpTransportManager(ExclusiveTcpTransportManagerRegistration registration,
                                            TcpChannelListener channelListener, IPAddress ipAddressAny, UriHostNameType ipHostNameType)
        {
            ApplyListenerSettings(channelListener);

            this.listenSocket = channelListener.GetListenSocket(ipHostNameType);
            if (this.listenSocket != null)
            {
                this.ipAddress = ((IPEndPoint)this.listenSocket.LocalEndPoint).Address;
            }
            else if (channelListener.Uri.HostNameType == ipHostNameType)
            {
                this.ipAddress = IPAddress.Parse(channelListener.Uri.DnsSafeHost);
            }
            else
            {
                this.ipAddress = ipAddressAny;
            }

            this.listenBacklog = channelListener.ListenBacklog;
            this.registration  = registration;
        }
コード例 #16
0
 public SharedTcpTransportManager(Uri listenUri, TcpChannelListener channelListener)
 {
     this.HostNameComparisonMode = channelListener.HostNameComparisonMode;
     this.listenUri = listenUri;
     base.ApplyListenerSettings(channelListener);
 }
コード例 #17
0
 protected virtual void OnSelecting(TcpChannelListener channelListener)
 {
 }