Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- XmlDocumentFragment.cs
- RijndaelManaged.cs
- TreeBuilderBamlTranslator.cs
- RelativeSource.cs
- BrowserCapabilitiesCompiler.cs
- SqlDataSourceView.cs
- List.cs
- ResetableIterator.cs
- XmlMapping.cs
- MessageQueueKey.cs
- PerformanceCounterLib.cs
- SQLBoolean.cs
- DigitShape.cs
- ImageConverter.cs
- WebDescriptionAttribute.cs
- TimeSpanParse.cs
- CodeRemoveEventStatement.cs
- Rotation3DAnimationBase.cs
- MsmqException.cs
- TrustManager.cs
- SpecularMaterial.cs
- SByteConverter.cs
- IDQuery.cs
- DataGridViewCellPaintingEventArgs.cs
- DaylightTime.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- ExpandCollapsePattern.cs
- ProcessInfo.cs
- HostingEnvironmentWrapper.cs
- SqlNotificationRequest.cs
- CodeGen.cs
- LogLogRecord.cs
- Identity.cs
- IIS7WorkerRequest.cs
- StylusShape.cs
- FixedSOMLineRanges.cs
- Stackframe.cs
- Point.cs
- OpCellTreeNode.cs
- BitmapEffectvisualstate.cs
- CodePageUtils.cs
- RegexMatch.cs
- ExtentKey.cs
- ContainerUIElement3D.cs
- MethodAccessException.cs
- DefaultBinder.cs
- CursorInteropHelper.cs
- WindowsGraphicsCacheManager.cs
- CustomAttributeSerializer.cs
- PipelineComponent.cs
- TimeSpanParse.cs
- XmlTextEncoder.cs
- PowerStatus.cs
- DefaultSection.cs
- PartBasedPackageProperties.cs
- OverflowException.cs
- OpacityConverter.cs
- SID.cs
- TraceHandler.cs
- XamlReaderHelper.cs
- UnauthorizedAccessException.cs
- Encoder.cs
- EpmTargetTree.cs
- DifferencingCollection.cs
- AnimatedTypeHelpers.cs
- MobileResource.cs
- CorrelationManager.cs
- sqlmetadatafactory.cs
- ExponentialEase.cs
- BindingList.cs
- RubberbandSelector.cs
- COM2PictureConverter.cs
- MsmqIntegrationInputChannel.cs
- TextRange.cs
- JsonDeserializer.cs
- CodeBinaryOperatorExpression.cs
- WpfKnownType.cs
- SmtpFailedRecipientsException.cs
- SkipStoryboardToFill.cs
- EntityTypeBase.cs
- DoWorkEventArgs.cs
- SynchronousChannel.cs
- DeclarativeCatalogPart.cs
- RuleSettingsCollection.cs
- RadioButtonFlatAdapter.cs
- BlurBitmapEffect.cs
- SaveWorkflowCommand.cs
- WindowsToolbar.cs
- PointAnimation.cs
- WebPartVerbCollection.cs
- UnsafeNativeMethods.cs
- ReachDocumentReferenceCollectionSerializerAsync.cs
- DataBoundControlAdapter.cs
- ManagedWndProcTracker.cs
- OleDbPropertySetGuid.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- IntSecurity.cs
- Decoder.cs
- XmlSchemaComplexContentRestriction.cs
- ZipIOBlockManager.cs