public static ServicePoint FindServicePoint(Uri address, IWebProxy proxy) { if (address == null) { throw new ArgumentNullException("address"); } var origAddress = new Uri(address.Scheme + "://" + address.Authority); bool usesProxy = false; bool useConnect = false; if (proxy != null && !proxy.IsBypassed(address)) { usesProxy = true; bool isSecure = address.Scheme == "https"; address = proxy.GetProxy(address); if (address.Scheme != "http") { throw new NotSupportedException("Proxy scheme not supported."); } if (isSecure && address.Scheme == "http") { useConnect = true; } } address = new Uri(address.Scheme + "://" + address.Authority); var key = new SPKey(origAddress, usesProxy ? address : null, useConnect); lock (servicePoints) { if (servicePoints.TryGetValue(key, out var sp)) { return(sp); } if (maxServicePoints > 0 && servicePoints.Count >= maxServicePoints) { throw new InvalidOperationException("maximum number of service points reached"); } int limit; #if MOBILE limit = defaultConnectionLimit; #else string addr = address.ToString(); limit = (int)manager.GetMaxConnections(addr); #endif sp = new ServicePoint(key, address, limit, maxServicePointIdleTime); sp.Expect100Continue = expectContinue; sp.UseNagleAlgorithm = useNagle; sp.UsesProxy = usesProxy; sp.UseConnect = useConnect; sp.SetTcpKeepAlive(tcp_keepalive, tcp_keepalive_time, tcp_keepalive_interval); return(servicePoints.GetOrAdd(key, sp)); } }
public override bool Equals(object obj) { SPKey sPKey = obj as SPKey; if (obj == null) { return(false); } return(uri.Equals(sPKey.uri) && sPKey.use_connect == use_connect); }
/// <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(Uri address, IWebProxy proxy) { if (address == null) { throw new ArgumentNullException("address"); } 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 Uri(address.Scheme + "://" + address.Authority); ServicePoint servicePoint = null; lock (servicePoints) { SPKey key = new SPKey(address, flag); servicePoint = (servicePoints[key] as ServicePoint); if (servicePoint != null) { return(servicePoint); } if (maxServicePoints > 0 && servicePoints.Count >= maxServicePoints) { throw new InvalidOperationException("maximum number of service points reached"); } string text = address.ToString(); int connectionLimit = defaultConnectionLimit; servicePoint = new ServicePoint(address, connectionLimit, maxServicePointIdleTime); servicePoint.Expect100Continue = expectContinue; servicePoint.UseNagleAlgorithm = useNagle; servicePoint.UsesProxy = usesProxy; servicePoint.UseConnect = flag; servicePoints.Add(key, servicePoint); return(servicePoint); } }
public override bool Equals(object obj) { SPKey other = obj as SPKey; if (obj == null) { return(false); } if (!uri.Equals(other.uri)) { return(false); } if (use_connect != other.use_connect || UsesProxy != other.UsesProxy) { return(false); } if (UsesProxy && !proxy.Equals(other.proxy)) { return(false); } return(true); }
public static ServicePoint FindServicePoint(Uri address, IWebProxy proxy) { if (address == null) { throw new ArgumentNullException("address"); } RecycleServicePoints(); bool usesProxy = false; bool useConnect = false; if (proxy != null && !proxy.IsBypassed(address)) { usesProxy = true; bool isSecure = address.Scheme == "https"; address = proxy.GetProxy(address); if (address.Scheme != "http" && !isSecure) { throw new NotSupportedException("Proxy scheme not supported."); } if (isSecure && address.Scheme == "http") { useConnect = true; } } address = new Uri(address.Scheme + "://" + address.Authority); ServicePoint sp = null; lock (servicePoints) { SPKey key = new SPKey(address, useConnect); sp = servicePoints [key] as ServicePoint; if (sp != null) { return(sp); } if (maxServicePoints > 0 && servicePoints.Count >= maxServicePoints) { throw new InvalidOperationException("maximum number of service points reached"); } string addr = address.ToString(); #if MONOTOUCH int limit = defaultConnectionLimit; #else int limit = (int)manager.GetMaxConnections(addr); #endif sp = new ServicePoint(address, limit, maxServicePointIdleTime); #if NET_1_1 sp.Expect100Continue = expectContinue; sp.UseNagleAlgorithm = useNagle; #endif sp.UsesProxy = usesProxy; sp.UseConnect = useConnect; servicePoints.Add(key, sp); } return(sp); }
public static ServicePoint FindServicePoint (Uri address, IWebProxy proxy) { if (address == null) throw new ArgumentNullException ("address"); RecycleServicePoints (); bool usesProxy = false; bool useConnect = false; if (proxy != null && !proxy.IsBypassed(address)) { usesProxy = true; bool isSecure = address.Scheme == "https"; address = proxy.GetProxy (address); if (address.Scheme != "http" && !isSecure) throw new NotSupportedException ("Proxy scheme not supported."); if (isSecure && address.Scheme == "http") useConnect = true; } address = new Uri (address.Scheme + "://" + address.Authority); ServicePoint sp = null; lock (servicePoints) { SPKey key = new SPKey (address, useConnect); sp = servicePoints [key] as ServicePoint; if (sp != null) return sp; if (maxServicePoints > 0 && servicePoints.Count >= maxServicePoints) throw new InvalidOperationException ("maximum number of service points reached"); string addr = address.ToString (); #if NET_2_1 int limit = defaultConnectionLimit; #else int limit = (int) manager.GetMaxConnections (addr); #endif sp = new ServicePoint (address, limit, maxServicePointIdleTime); sp.Expect100Continue = expectContinue; sp.UseNagleAlgorithm = useNagle; sp.UsesProxy = usesProxy; sp.UseConnect = useConnect; sp.SetTcpKeepAlive (tcp_keepalive, tcp_keepalive_time, tcp_keepalive_interval); servicePoints.Add (key, sp); } return sp; }