Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / ConnectionPoolManager.cs / 1305376 / 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; } // Gets the connection pool for the specified service point (if it exists) and // invokes ForceCleanup to gracefully clean up any connections in the pool. // // preconditions: none // // postconditions: if a connection pool for the specified servicepoint and group name // exists, any open connections that are not in use will be gracefully cleaned up. // // Note: this will not destroy the connection pool itself so any future objects that // need that connection pool will still be able to access it to create new connections // and any objects using connections in the pool will still be able to return them internal static void CleanupConnectionPool(ServicePoint servicePoint, string groupName) { string key = GenerateKey(servicePoint.Host, servicePoint.Port, groupName); lock (InternalSyncObject) { ConnectionPool connectionPool = (ConnectionPool)(m_ConnectionPools[key]); if (connectionPool != null) { connectionPool.ForceCleanup(); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// 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; } // Gets the connection pool for the specified service point (if it exists) and // invokes ForceCleanup to gracefully clean up any connections in the pool. // // preconditions: none // // postconditions: if a connection pool for the specified servicepoint and group name // exists, any open connections that are not in use will be gracefully cleaned up. // // Note: this will not destroy the connection pool itself so any future objects that // need that connection pool will still be able to access it to create new connections // and any objects using connections in the pool will still be able to return them internal static void CleanupConnectionPool(ServicePoint servicePoint, string groupName) { string key = GenerateKey(servicePoint.Host, servicePoint.Port, groupName); lock (InternalSyncObject) { ConnectionPool connectionPool = (ConnectionPool)(m_ConnectionPools[key]); if (connectionPool != null) { connectionPool.ForceCleanup(); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DbProviderFactory.cs
- oledbmetadatacollectionnames.cs
- SimpleBitVector32.cs
- ImageIndexConverter.cs
- IISUnsafeMethods.cs
- ArraySubsetEnumerator.cs
- StateRuntime.cs
- CacheModeConverter.cs
- ApplicationId.cs
- TransactionChannelListener.cs
- ActivityBuilderHelper.cs
- COAUTHIDENTITY.cs
- ClientBuildManagerCallback.cs
- localization.cs
- WebPartMovingEventArgs.cs
- EditingScopeUndoUnit.cs
- SafeSecurityHelper.cs
- Model3DCollection.cs
- CustomAttributeBuilder.cs
- GridEntryCollection.cs
- AesManaged.cs
- WindowsListViewItem.cs
- FormViewDeletedEventArgs.cs
- AvTraceDetails.cs
- isolationinterop.cs
- Event.cs
- CreateUserWizardAutoFormat.cs
- AliasedSlot.cs
- EntityModelBuildProvider.cs
- UnsafeNativeMethodsCLR.cs
- TableLayoutSettingsTypeConverter.cs
- ColorConvertedBitmapExtension.cs
- DictionarySectionHandler.cs
- ReadOnlyTernaryTree.cs
- PropertyEmitter.cs
- _NTAuthentication.cs
- DoubleCollectionConverter.cs
- BufferModesCollection.cs
- HttpFileCollection.cs
- HtmlSelect.cs
- XmlTextAttribute.cs
- WinEventWrap.cs
- XmlSiteMapProvider.cs
- XmlSchemaSimpleType.cs
- SizeConverter.cs
- CloudCollection.cs
- ArrowControl.xaml.cs
- BreakRecordTable.cs
- StringToken.cs
- CalendarAutomationPeer.cs
- DomainLiteralReader.cs
- VirtualDirectoryMapping.cs
- VirtualPathProvider.cs
- EventlogProvider.cs
- GenericXmlSecurityToken.cs
- PersistenceException.cs
- ModelFunctionTypeElement.cs
- GridViewAutomationPeer.cs
- VariableDesigner.xaml.cs
- GridView.cs
- Int16KeyFrameCollection.cs
- Quad.cs
- StreamReader.cs
- FilteredXmlReader.cs
- InfoCardTrace.cs
- PageRanges.cs
- AuthenticateEventArgs.cs
- _ChunkParse.cs
- StylusOverProperty.cs
- Helpers.cs
- FileRecordSequenceCompletedAsyncResult.cs
- CaseInsensitiveHashCodeProvider.cs
- FatalException.cs
- XmlReflectionImporter.cs
- MetafileHeader.cs
- EvidenceTypeDescriptor.cs
- HtmlInputHidden.cs
- UnrecognizedAssertionsBindingElement.cs
- ListenerElementsCollection.cs
- LoopExpression.cs
- SHA1CryptoServiceProvider.cs
- ProxyWebPartConnectionCollection.cs
- PropertyValueEditor.cs
- ApplicationBuildProvider.cs
- ECDiffieHellmanCng.cs
- TrackingValidationObjectDictionary.cs
- DockPattern.cs
- Clause.cs
- Simplifier.cs
- RuntimeVariablesExpression.cs
- WebPartExportVerb.cs
- SimpleApplicationHost.cs
- EditableTreeList.cs
- XmlAutoDetectWriter.cs
- AddValidationError.cs
- SQLUtility.cs
- BlurBitmapEffect.cs
- MultilineStringConverter.cs
- Module.cs
- CodeGroup.cs