Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Net / System / Net / ConnectionPoolManager.cs / 1 / ConnectionPoolManager.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net { using System; using System.Collections; using System.Diagnostics; using System.Security; using System.Security.Permissions; using System.Threading; using System.Globalization; internal class ConnectionPoolManager { private static Hashtable m_ConnectionPools = new Hashtable(); // Hashtable used for connection pools private static object s_InternalSyncObject; private ConnectionPoolManager() { } private static object InternalSyncObject { get { if (s_InternalSyncObject == null) { object o = new Object(); Interlocked.CompareExchange(ref s_InternalSyncObject, o, null); } return s_InternalSyncObject; } } /*internal static ConnectionPool[] ConnectionPools { get { lock(InternalSyncObject) { ConnectionPool [] connectionPools = new ConnectionPool[m_ConnectionPools.Count]; m_ConnectionPools.CopyTo(connectionPools, 0); return connectionPools; } } } */ private static string GenerateKey(string hostName, int port, string groupName) { return hostName+"\r"+port.ToString(NumberFormatInfo.InvariantInfo)+"\r"+groupName; } internal static ConnectionPool GetConnectionPool(ServicePoint servicePoint, string groupName, CreateConnectionDelegate createConnectionCallback) { string key = GenerateKey(servicePoint.Host, servicePoint.Port, groupName); lock(InternalSyncObject) { ConnectionPool connectionPool = (ConnectionPool) m_ConnectionPools[key]; if (connectionPool == null) { connectionPool = new ConnectionPool(servicePoint, servicePoint.ConnectionLimit, 0, servicePoint.MaxIdleTime, createConnectionCallback); m_ConnectionPools[key] = connectionPool; } return connectionPool; } } /* internal static ConnectionPool GetConnectionPool(string hostName, int port, string groupName, CreateConnectionDelegate createConnectionCallback) { string key = hostName + "\r" + port.ToString(NumberFormatInfo.InvariantInfo) + "\r" + groupName; lock(InternalSyncObject) { ConnectionPool connectionPool = (ConnectionPool) m_ConnectionPools[key]; if (connectionPool == null) { ServicePoint servicePoint = ServicePointManager.FindServicePoint(new Uri("sockets://" + hostName + ":" + port.ToString(NumberFormatInfo.InvariantInfo)), null); connectionPool = new ConnectionPool(servicePoint, m_DefaultMaxPool, 0, servicePoint.MaxIdleTime, createConnectionCallback); m_ConnectionPools[key] = connectionPool; } return connectionPool; } } */ internal static bool RemoveConnectionPool(ServicePoint servicePoint, string groupName) { string key = GenerateKey(servicePoint.Host, servicePoint.Port, groupName); lock(InternalSyncObject) { ConnectionPool connectionPool = (ConnectionPool)(m_ConnectionPools[key]); if(connectionPool != null) { m_ConnectionPools[key] = null; m_ConnectionPools.Remove(key); return true; } } return false; } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GenericTransactionFlowAttribute.cs
- BooleanKeyFrameCollection.cs
- SoapEnumAttribute.cs
- WCFModelStrings.Designer.cs
- CodeArrayIndexerExpression.cs
- RequestCachePolicyConverter.cs
- Pair.cs
- XmlResolver.cs
- __FastResourceComparer.cs
- webbrowsersite.cs
- CapabilitiesAssignment.cs
- TextAutomationPeer.cs
- ItemContainerGenerator.cs
- PrefixQName.cs
- LinearGradientBrush.cs
- RestClientProxyHandler.cs
- DataServiceException.cs
- BaseTransportHeaders.cs
- DefinitionBase.cs
- WebBrowserUriTypeConverter.cs
- ArrayElementGridEntry.cs
- DataBindingHandlerAttribute.cs
- StringComparer.cs
- ChannelCacheSettings.cs
- CodeTypeMember.cs
- DeferredReference.cs
- SizeChangedEventArgs.cs
- CommunicationObjectAbortedException.cs
- DiffuseMaterial.cs
- RectangleConverter.cs
- DataConnectionHelper.cs
- IssuanceLicense.cs
- PropertyKey.cs
- FunctionNode.cs
- XmlDocumentFragment.cs
- EntityDataSourceChangedEventArgs.cs
- PropertyConverter.cs
- TypeNameHelper.cs
- SortDescriptionCollection.cs
- ScriptRegistrationManager.cs
- HttpServerUtilityBase.cs
- ObservableCollection.cs
- SHA256.cs
- HighlightComponent.cs
- TheQuery.cs
- TextUtf8RawTextWriter.cs
- SHA1Managed.cs
- ViewManager.cs
- WebEvents.cs
- QuestionEventArgs.cs
- TimeSpanStorage.cs
- Triplet.cs
- Splitter.cs
- XmlNotation.cs
- BrowserCapabilitiesCompiler.cs
- ThreadStaticAttribute.cs
- ProvideValueServiceProvider.cs
- CodeCastExpression.cs
- XmlCountingReader.cs
- PeerInvitationResponse.cs
- DataGridViewEditingControlShowingEventArgs.cs
- DataGridClipboardCellContent.cs
- StringUtil.cs
- controlskin.cs
- WaitHandle.cs
- LayoutDump.cs
- DefaultAsyncDataDispatcher.cs
- LoadWorkflowByKeyAsyncResult.cs
- ToolStripItemClickedEventArgs.cs
- SiteOfOriginContainer.cs
- JsonWriter.cs
- DataTableExtensions.cs
- PropertyGrid.cs
- InheritanceContextChangedEventManager.cs
- DbMetaDataFactory.cs
- XmlSchemaAppInfo.cs
- EntityProviderServices.cs
- panel.cs
- ToolStripDropDownClosedEventArgs.cs
- CommonProperties.cs
- Control.cs
- SqlException.cs
- SBCSCodePageEncoding.cs
- LinkButton.cs
- Menu.cs
- Label.cs
- Triplet.cs
- Shared.cs
- Operators.cs
- DbConnectionInternal.cs
- QualifiedId.cs
- SecureStringHasher.cs
- SqlDataSourceEnumerator.cs
- Executor.cs
- XmlToDatasetMap.cs
- Int32Storage.cs
- SortQuery.cs
- ConfigurationLocation.cs
- DbUpdateCommandTree.cs
- StrongName.cs