Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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; } } } // 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; } } } // 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
- TextEditorDragDrop.cs
- DataSet.cs
- _NTAuthentication.cs
- ByteStack.cs
- OdbcDataReader.cs
- Validator.cs
- ProtocolsConfigurationEntry.cs
- AssociationProvider.cs
- XmlSerializer.cs
- WriterOutput.cs
- DependencyObject.cs
- AnimatedTypeHelpers.cs
- SiblingIterators.cs
- DesignTimeValidationFeature.cs
- RegexCharClass.cs
- NameValuePermission.cs
- TextParentUndoUnit.cs
- EntityClassGenerator.cs
- FillBehavior.cs
- BulletedList.cs
- CommonXSendMessage.cs
- HtmlInputFile.cs
- DesignTimeVisibleAttribute.cs
- WebPartCatalogCloseVerb.cs
- Int32KeyFrameCollection.cs
- TemplateKeyConverter.cs
- SamlAuthorityBinding.cs
- TogglePattern.cs
- SecurityTokenTypes.cs
- VisualStyleTypesAndProperties.cs
- NameTable.cs
- PipeStream.cs
- ExceptionHelpers.cs
- SafeNativeMethods.cs
- SHA1.cs
- ProviderSettingsCollection.cs
- OleDbStruct.cs
- CheckBoxDesigner.cs
- TextTreeTextElementNode.cs
- _DomainName.cs
- ServiceMetadataExtension.cs
- Helpers.cs
- JapaneseLunisolarCalendar.cs
- PropertyInfo.cs
- SEHException.cs
- SqlDataSource.cs
- XmlAnyElementAttributes.cs
- ListViewItem.cs
- LoginDesigner.cs
- DispatcherExceptionFilterEventArgs.cs
- TypefaceMap.cs
- Avt.cs
- _NetRes.cs
- ScriptIgnoreAttribute.cs
- SqlDataSourceCustomCommandPanel.cs
- BaseTemplateCodeDomTreeGenerator.cs
- SecurityHelper.cs
- CommonProperties.cs
- DefaultPrintController.cs
- ReferencedAssembly.cs
- DesignerActionListCollection.cs
- COM2TypeInfoProcessor.cs
- EntityCodeGenerator.cs
- ViewLoader.cs
- DataRowComparer.cs
- ObjectMaterializedEventArgs.cs
- SQLGuid.cs
- SerializationHelper.cs
- VirtualPath.cs
- FastEncoderWindow.cs
- WebDescriptionAttribute.cs
- SqlXmlStorage.cs
- WebRequestModuleElementCollection.cs
- ComplexObject.cs
- COM2FontConverter.cs
- UriSectionData.cs
- SqlBuilder.cs
- Vector3DAnimationUsingKeyFrames.cs
- HyperlinkAutomationPeer.cs
- DoubleMinMaxAggregationOperator.cs
- EncoderParameter.cs
- MenuCommands.cs
- ColumnBinding.cs
- AbstractDataSvcMapFileLoader.cs
- WindowsGrip.cs
- AnnotationResource.cs
- EpmSyndicationContentSerializer.cs
- AdapterDictionary.cs
- Button.cs
- ToolboxDataAttribute.cs
- XPathMessageFilter.cs
- ConstrainedDataObject.cs
- DataView.cs
- MediaContext.cs
- ImageList.cs
- CompiledRegexRunnerFactory.cs
- ObjectStateFormatter.cs
- Nullable.cs
- X509Certificate2Collection.cs
- MultiAsyncResult.cs