Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- DependencyPropertyKey.cs
- SamlConditions.cs
- QueueException.cs
- TimelineGroup.cs
- CustomAttributeFormatException.cs
- Number.cs
- TextServicesCompartmentContext.cs
- WebServiceParameterData.cs
- TimeSpanMinutesConverter.cs
- SiteOfOriginPart.cs
- KeyBinding.cs
- MessageQueuePermission.cs
- DrawingContextDrawingContextWalker.cs
- RangeValuePatternIdentifiers.cs
- Soap.cs
- Rotation3D.cs
- TextServicesDisplayAttribute.cs
- TypefaceMap.cs
- ChineseLunisolarCalendar.cs
- CodeConditionStatement.cs
- ShapingWorkspace.cs
- CommandBindingCollection.cs
- TagPrefixCollection.cs
- PartialClassGenerationTaskInternal.cs
- ProxyHelper.cs
- ToolBarButton.cs
- UnauthorizedAccessException.cs
- SafeRightsManagementPubHandle.cs
- EditorPartChrome.cs
- SelectionPatternIdentifiers.cs
- TextOptionsInternal.cs
- WebContext.cs
- TagPrefixInfo.cs
- ContentValidator.cs
- ViewValidator.cs
- GenericParameterDataContract.cs
- BaseTreeIterator.cs
- ProcessModuleDesigner.cs
- ButtonFieldBase.cs
- KeyProperty.cs
- Profiler.cs
- ExtractedStateEntry.cs
- PathSegmentCollection.cs
- DispatcherOperation.cs
- ObjectStateManagerMetadata.cs
- EditorBrowsableAttribute.cs
- UiaCoreApi.cs
- SqlConnectionPoolProviderInfo.cs
- PnrpPermission.cs
- StoreContentChangedEventArgs.cs
- GridView.cs
- ListViewGroupItemCollection.cs
- AutomationProperties.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- DecimalAnimationBase.cs
- CurrencyWrapper.cs
- WorkflowEventArgs.cs
- ReliableDuplexSessionChannel.cs
- String.cs
- ToolBarButtonClickEvent.cs
- HttpHeaderCollection.cs
- SafeMarshalContext.cs
- SystemBrushes.cs
- ObjectStateFormatter.cs
- BitmapImage.cs
- DocumentScope.cs
- DependentTransaction.cs
- ExpressionBuilderCollection.cs
- ConstructorArgumentAttribute.cs
- FtpWebRequest.cs
- SystemFonts.cs
- NamespaceEmitter.cs
- Underline.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- Baml2006ReaderContext.cs
- IISMapPath.cs
- DropDownList.cs
- XmlHierarchicalEnumerable.cs
- MemberInfoSerializationHolder.cs
- EnvelopedPkcs7.cs
- SignatureGenerator.cs
- Button.cs
- SmiContext.cs
- TraceFilter.cs
- TableCell.cs
- SamlAssertionKeyIdentifierClause.cs
- EntityContainer.cs
- MailWriter.cs
- ResourceCategoryAttribute.cs
- LicenseManager.cs
- RoleManagerEventArgs.cs
- GraphicsState.cs
- Queue.cs
- FocusChangedEventArgs.cs
- DataGridViewRowConverter.cs
- DataSourceCache.cs
- IxmlLineInfo.cs
- FieldCollectionEditor.cs
- TrustLevelCollection.cs
- BackgroundFormatInfo.cs