Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / ExclusiveTcpTransportManager.cs / 1 / ExclusiveTcpTransportManager.cs
//---------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------------------- namespace System.ServiceModel.Channels { using System.Collections.Generic; using System.ServiceModel; using System.IO; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using System.ServiceModel.Diagnostics; using System.Diagnostics; sealed class ExclusiveTcpTransportManager : TcpTransportManager, ISocketListenerSettings { ConnectionDemuxer connectionDemuxer; IConnectionListener connectionListener; IPAddress ipAddress; int listenBacklog; Socket listenSocket; ExclusiveTcpTransportManagerRegistration registration; 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; } public IPAddress IPAddress { get { return this.ipAddress; } } public int ListenBacklog { get { return this.listenBacklog; } } int ISocketListenerSettings.BufferSize { get { return ConnectionBufferSize; } } bool ISocketListenerSettings.TeredoEnabled { get { return registration.TeredoEnabled; } } int ISocketListenerSettings.ListenBacklog { get { return ListenBacklog; } } internal override void OnOpen() { SocketConnectionListener socketListener = null; if (this.listenSocket != null) { socketListener = new SocketConnectionListener(this.listenSocket, this, false); this.listenSocket = null; } else { int port = this.registration.ListenUri.Port; if (port == -1) port = TcpUri.DefaultPort; socketListener = new SocketConnectionListener(new IPEndPoint(ipAddress, port), this, false); } connectionListener = new BufferedConnectionListener(socketListener, MaxOutputDelay, ConnectionBufferSize); if (DiagnosticUtility.ShouldUseActivity) { connectionListener = new TracingConnectionListener(connectionListener, this.registration.ListenUri.ToString(), false); } connectionDemuxer = new ConnectionDemuxer(connectionListener, MaxPendingAccepts, MaxPendingConnections, ChannelInitializationTimeout, IdleTimeout, MaxPooledConnections, OnGetTransportFactorySettings, OnGetSingletonMessageHandler, OnHandleServerSessionPreamble, OnDemuxerError); bool startedDemuxing = false; try { connectionDemuxer.StartDemuxing(); startedDemuxing = true; } finally { if (!startedDemuxing) { connectionDemuxer.Dispose(); } } } internal override void OnClose() { connectionDemuxer.Dispose(); connectionListener.Dispose(); this.registration.OnClose(this); } } class ExclusiveTcpTransportManagerRegistration : TransportManagerRegistration { int connectionBufferSize; TimeSpan channelInitializationTimeout; TimeSpan idleTimeout; int maxPooledConnections; bool teredoEnabled; int listenBacklog; TimeSpan maxOutputDelay; int maxPendingConnections; int maxPendingAccepts; ExclusiveTcpTransportManager ipv4TransportManager; ExclusiveTcpTransportManager ipv6TransportManager; 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; } public bool TeredoEnabled { get { return this.teredoEnabled; } } public void OnClose(TcpTransportManager manager) { if (manager == this.ipv4TransportManager) { this.ipv4TransportManager = null; } else if (manager == this.ipv6TransportManager) { this.ipv6TransportManager = null; } else { DiagnosticUtility.DebugAssert("Unknown transport manager passed to OnClose()."); } if ((this.ipv4TransportManager == null) && (this.ipv6TransportManager == null)) { TcpChannelListener.StaticTransportManagerTable.UnregisterUri(this.ListenUri, this.HostNameComparisonMode); } } 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)); } void ProcessSelection(TcpChannelListener channelListener, IPAddress ipAddressAny, UriHostNameType ipHostNameType, ref ExclusiveTcpTransportManager transportManager, IListresult) { if (transportManager == null) { transportManager = new ExclusiveTcpTransportManager(this, channelListener, ipAddressAny, ipHostNameType); } result.Add(transportManager); } public override IList Select(TransportChannelListener channelListener) { bool useIPv4 = (this.ListenUri.HostNameType != UriHostNameType.IPv6) && Socket.SupportsIPv4; bool useIPv6 = (this.ListenUri.HostNameType != UriHostNameType.IPv4) && Socket.OSSupportsIPv6; TcpChannelListener tcpListener = (TcpChannelListener)channelListener; if (!this.IsCompatible(tcpListener, useIPv4, useIPv6)) { return null; } IList result = new List (); 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; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CriticalHandle.cs
- SimpleWebHandlerParser.cs
- ImageBrush.cs
- ArgumentException.cs
- QueryRewriter.cs
- XPathPatternParser.cs
- Int32EqualityComparer.cs
- HttpModuleAction.cs
- PartialArray.cs
- LogStream.cs
- ElementAtQueryOperator.cs
- GlyphRun.cs
- XmlConverter.cs
- TableChangeProcessor.cs
- DeviceContext2.cs
- TableLayoutStyleCollection.cs
- PathParser.cs
- WindowsStartMenu.cs
- ImageBrush.cs
- RadioButtonRenderer.cs
- Crc32.cs
- _NetRes.cs
- Variable.cs
- FilterQueryOptionExpression.cs
- FlowNode.cs
- DataGridViewTextBoxCell.cs
- BrowserTree.cs
- FixedSOMSemanticBox.cs
- SemaphoreSecurity.cs
- ListViewInsertionMark.cs
- AsyncOperation.cs
- ExpanderAutomationPeer.cs
- StringUtil.cs
- SafeEventLogWriteHandle.cs
- XappLauncher.cs
- VirtualizingPanel.cs
- IisTraceListener.cs
- SecurityElement.cs
- PathFigureCollectionConverter.cs
- SQLString.cs
- Int16Animation.cs
- Number.cs
- DrawingAttributes.cs
- UriTemplateTableMatchCandidate.cs
- ReliabilityContractAttribute.cs
- GridErrorDlg.cs
- DataSourceProvider.cs
- DataGridViewCellStyleConverter.cs
- MouseWheelEventArgs.cs
- RSAProtectedConfigurationProvider.cs
- EmptyEnumerable.cs
- Hex.cs
- WindowInteropHelper.cs
- Typography.cs
- ManagedWndProcTracker.cs
- EFAssociationProvider.cs
- FileController.cs
- QueryRelOp.cs
- mda.cs
- StorageFunctionMapping.cs
- SpellerHighlightLayer.cs
- MD5CryptoServiceProvider.cs
- EncoderReplacementFallback.cs
- SafeFileMappingHandle.cs
- lengthconverter.cs
- InternalConfigRoot.cs
- CurrentChangingEventArgs.cs
- SocketException.cs
- SingleResultAttribute.cs
- UnsafeNativeMethods.cs
- DataColumnMapping.cs
- Int32RectConverter.cs
- StreamingContext.cs
- SoapFormatter.cs
- FileDocument.cs
- SimpleExpression.cs
- CustomAttributeSerializer.cs
- Compilation.cs
- Pen.cs
- ScriptingProfileServiceSection.cs
- BitmapFrameEncode.cs
- ConfigPathUtility.cs
- SecUtil.cs
- Point4D.cs
- SqlCommand.cs
- PropertyRecord.cs
- HtmlControlPersistable.cs
- CodeIdentifier.cs
- StringUtil.cs
- TypeElementCollection.cs
- Point3DIndependentAnimationStorage.cs
- PersonalizationStateInfoCollection.cs
- WebPartExportVerb.cs
- IssuanceTokenProviderState.cs
- HtmlCommandAdapter.cs
- TdsParserHelperClasses.cs
- TemplatePropertyEntry.cs
- TabRenderer.cs
- LinqDataSourceValidationException.cs
- StrongNameUtility.cs