public override IList <TransportManager> Select(TransportChannelListener channelListener) { bool useIPv4 = (ListenUri.HostNameType != UriHostNameType.IPv6) && Socket.OSSupportsIPv4; bool useIPv6 = (ListenUri.HostNameType != UriHostNameType.IPv4) && Socket.OSSupportsIPv6; TcpChannelListener tcpListener = (TcpChannelListener)channelListener; if (!IsCompatible(tcpListener, useIPv4, useIPv6)) { return(null); } IList <TransportManager> result = new List <TransportManager>(); if (useIPv4) { ProcessSelection(tcpListener, IPAddress.Any, UriHostNameType.IPv4, ref ipv4TransportManager, result); } if (useIPv6) { ProcessSelection(tcpListener, IPAddress.IPv6Any, UriHostNameType.IPv6, ref ipv6TransportManager, result); } return(result); }
bool IsCompatible(TcpChannelListener channelListener, bool useIPv4, bool useIPv6) { if (channelListener.InheritBaseAddressSettings) { return(true); } if (useIPv6) { if (!channelListener.IsScopeIdCompatible(HostNameComparisonMode, ListenUri)) { return(false); } } return(/*!channelListener.PortSharingEnabled * &&*/(useIPv4 || useIPv6) && (channelInitializationTimeout == channelListener.ChannelInitializationTimeout) && (idleTimeout == channelListener.IdleTimeout) && (maxPooledConnections == channelListener.MaxPooledConnections) && (connectionBufferSize == channelListener.ConnectionBufferSize) && (listenBacklog == channelListener.ListenBacklog) && (maxPendingConnections == channelListener.MaxPendingConnections) && (maxOutputDelay == channelListener.MaxOutputDelay) && (maxPendingAccepts == channelListener.MaxPendingAccepts)); }
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; } } baseUri = baseAddress; ValidateUri(fullUri); uri = fullUri; }
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); }
public ExclusiveTcpTransportManagerRegistration(Uri listenUri, TcpChannelListener channelListener) : base(listenUri, channelListener.HostNameComparisonMode) { connectionBufferSize = channelListener.ConnectionBufferSize; channelInitializationTimeout = channelListener.ChannelInitializationTimeout; listenBacklog = channelListener.ListenBacklog; maxOutputDelay = channelListener.MaxOutputDelay; maxPendingConnections = channelListener.MaxPendingConnections; maxPendingAccepts = channelListener.MaxPendingAccepts; idleTimeout = channelListener.IdleTimeout; maxPooledConnections = channelListener.MaxPooledConnections; }
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); }
public ExclusiveTcpTransportManager(ExclusiveTcpTransportManagerRegistration registration, TcpChannelListener channelListener, IPAddress ipAddressAny, UriHostNameType ipHostNameType) { ApplyListenerSettings(channelListener); listenSocket = channelListener.GetListenSocket(ipHostNameType); if (listenSocket != null) { ipAddress = ((IPEndPoint)listenSocket.LocalEndPoint).Address; } else if (channelListener.Uri.HostNameType == ipHostNameType) { ipAddress = IPAddress.Parse(channelListener.Uri.DnsSafeHost); } else { ipAddress = ipAddressAny; } listenBacklog = channelListener.ListenBacklog; this.registration = registration; }
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); }