// // IncrementConnection // // Call to indicate that we now are starting a new // connection within this service point // internal void IncrementConnection() { GlobalLog.Print("IncrementConnection #" + m_CurrentConnections.ToString() + " #" + this.GetHashCode().ToString()); // we need these to be atomic operations lock (this) { m_CurrentConnections++; if (m_CurrentConnections == 1) { ServicePointManager.RemoveIdleServicePoint(this); } } }
// Methods internal ServicePoint GetServicePoint() { lock (locker) { if (hostChanged || servicePoint == null) { servicePoint = ServicePointManager.FindServicePoint(actualUri, proxy); hostChanged = false; } } return(servicePoint); }
/// <summary>Finds an existing <see cref="T:System.Net.ServicePoint" /> object or creates a new <see cref="T:System.Net.ServicePoint" /> object to manage communications with the specified <see cref="T:System.Uri" /> object.</summary> /// <returns>The <see cref="T:System.Net.ServicePoint" /> object that manages communications for the request.</returns> /// <param name="address">A <see cref="T:System.Uri" /> object that contains the address of the Internet resource to contact. </param> /// <param name="proxy">The proxy data for this request. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="address" /> is null. </exception> /// <exception cref="T:System.InvalidOperationException">The maximum number of <see cref="T:System.Net.ServicePoint" /> objects defined in <see cref="P:System.Net.ServicePointManager.MaxServicePoints" /> has been reached. </exception> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" /> /// </PermissionSet> public static ServicePoint FindServicePoint(System.Uri address, IWebProxy proxy) { if (address == null) { throw new ArgumentNullException("address"); } ServicePointManager.RecycleServicePoints(); bool usesProxy = false; bool flag = false; if (proxy != null && !proxy.IsBypassed(address)) { usesProxy = true; bool flag2 = address.Scheme == "https"; address = proxy.GetProxy(address); if (address.Scheme != "http" && !flag2) { throw new NotSupportedException("Proxy scheme not supported."); } if (flag2 && address.Scheme == "http") { flag = true; } } address = new System.Uri(address.Scheme + "://" + address.Authority); ServicePoint servicePoint = null; System.Collections.Specialized.HybridDictionary obj = ServicePointManager.servicePoints; lock (obj) { ServicePointManager.SPKey key = new ServicePointManager.SPKey(address, flag); servicePoint = (ServicePointManager.servicePoints[key] as ServicePoint); if (servicePoint != null) { return(servicePoint); } if (ServicePointManager.maxServicePoints > 0 && ServicePointManager.servicePoints.Count >= ServicePointManager.maxServicePoints) { throw new InvalidOperationException("maximum number of service points reached"); } string text = address.ToString(); int connectionLimit = ServicePointManager.defaultConnectionLimit; servicePoint = new ServicePoint(address, connectionLimit, ServicePointManager.maxServicePointIdleTime); servicePoint.Expect100Continue = ServicePointManager.expectContinue; servicePoint.UseNagleAlgorithm = ServicePointManager.useNagle; servicePoint.UsesProxy = usesProxy; servicePoint.UseConnect = flag; ServicePointManager.servicePoints.Add(key, servicePoint); } return(servicePoint); }
static HttpClient() { #if !Mono //返回域名多IP地址 ServicePointManager.EnableDnsRoundRobin = true; #endif ServicePointManager.DefaultConnectionLimit = ushort.MaxValue; ServicePointManager.MaxServicePoints = 0; ServicePointManager.MaxServicePointIdleTime = 100000; checked { int keep = (int)xHttpHandler.KeepAliveInterval; ServicePointManager.SetTcpKeepAlive(true, keep, keep); } ServicePointManager.CheckCertificateRevocationList = true; ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult); }
// // DecrementConnection // // Call to indicate that we now are removing // a connection within this connection group // internal void DecrementConnection() { GlobalLog.Print("DecrementConnection #" + m_CurrentConnections.ToString() + " #" + this.GetHashCode().ToString()); // we need these to be atomic operations lock (this) { m_CurrentConnections--; if (m_CurrentConnections == 0) { MarkIdle(); ServicePointManager.AddIdleServicePoint(this); } else if (m_CurrentConnections < 0) { m_CurrentConnections = 0; } } }
/// <summary>Finds an existing <see cref="T:System.Net.ServicePoint" /> object or creates a new <see cref="T:System.Net.ServicePoint" /> object to manage communications with the specified Uniform Resource Identifier (URI).</summary> /// <returns>The <see cref="T:System.Net.ServicePoint" /> object that manages communications for the request.</returns> /// <param name="uriString">The URI of the Internet resource to be contacted. </param> /// <param name="proxy">The proxy data for this request. </param> /// <exception cref="T:System.UriFormatException">The URI specified in <paramref name="uriString" /> is invalid. </exception> /// <exception cref="T:System.InvalidOperationException">The maximum number of <see cref="T:System.Net.ServicePoint" /> objects defined in <see cref="P:System.Net.ServicePointManager.MaxServicePoints" /> has been reached. </exception> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" /> /// </PermissionSet> public static ServicePoint FindServicePoint(string uriString, IWebProxy proxy) { return(ServicePointManager.FindServicePoint(new System.Uri(uriString), proxy)); }
/// <summary>Finds an existing <see cref="T:System.Net.ServicePoint" /> object or creates a new <see cref="T:System.Net.ServicePoint" /> object to manage communications with the specified <see cref="T:System.Uri" /> object.</summary> /// <returns>The <see cref="T:System.Net.ServicePoint" /> object that manages communications for the request.</returns> /// <param name="address">The <see cref="T:System.Uri" /> object of the Internet resource to contact. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="address" /> is null. </exception> /// <exception cref="T:System.InvalidOperationException">The maximum number of <see cref="T:System.Net.ServicePoint" /> objects defined in <see cref="P:System.Net.ServicePointManager.MaxServicePoints" /> has been reached. </exception> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" /> /// </PermissionSet> public static ServicePoint FindServicePoint(System.Uri address) { return(ServicePointManager.FindServicePoint(address, GlobalProxySelection.Select)); }