ServicePointManager.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // System.Net.ServicePointManager
  3. //
  4. // Author:
  5. // Lawrence Pit ([email protected])
  6. //
  7. using System;
  8. using System.Security.Cryptography.X509Certificates;
  9. //
  10. // notes:
  11. // A service point manager manages service points (duh!).
  12. // A service point maintains a list of connections (per scheme + authority
  13. // seems logical).
  14. // According to HttpWebRequest.ConnectionGroupName each connection group
  15. // creates additional connections. therefor, a service point has a hashtable
  16. // of connection groups where each value is a list of connections.
  17. //
  18. // when we need to make an HttpWebRequest, we need to do the following:
  19. // 1. find service point, given Uri and Proxy
  20. // 2. find connection group, given service point and group name
  21. // 3. find free connection in connection group, or create one (if ok due to limits)
  22. // 4. lease connection
  23. // 5. execute request
  24. // 6. when finished, return connection
  25. //
  26. namespace System.Net
  27. {
  28. public class ServicePointManager
  29. {
  30. private static ICertificatePolicy policy = null;
  31. private static int defaultConnectionLimit = DefaultPersistentConnectionLimit;
  32. private static int maxServicePointIdleTime = 900000; // 15 minutes
  33. private static int maxServicePoints = 0;
  34. // Fields
  35. public const int DefaultNonPersistentConnectionLimit = 4;
  36. public const int DefaultPersistentConnectionLimit = 2;
  37. // Constructors
  38. private ServicePointManager ()
  39. {
  40. }
  41. // Properties
  42. public static ICertificatePolicy CertificatePolicy {
  43. get { return policy; }
  44. set { policy = value; }
  45. }
  46. public static int DefaultConnectionLimit {
  47. get { return defaultConnectionLimit; }
  48. set {
  49. if (value < 0)
  50. throw new ArgumentOutOfRangeException ("value");
  51. defaultConnectionLimit = value;
  52. }
  53. }
  54. public static int MaxServicePointIdleTime {
  55. get {
  56. return maxServicePointIdleTime;
  57. }
  58. set {
  59. if (value < -2 || value > Int32.MaxValue)
  60. throw new ArgumentOutOfRangeException ("value");
  61. maxServicePointIdleTime = value;
  62. }
  63. }
  64. public static int MaxServicePoints {
  65. get {
  66. return maxServicePoints;
  67. }
  68. set {
  69. if (value < 0)
  70. throw new ArgumentException ("value");
  71. maxServicePoints = value;
  72. }
  73. }
  74. // Methods
  75. public static ServicePoint FindServicePoint (Uri address)
  76. {
  77. return FindServicePoint (address, GlobalProxySelection.Select);
  78. }
  79. public static ServicePoint FindServicePoint (string uriString, IWebProxy proxy)
  80. {
  81. return FindServicePoint (new Uri(uriString), proxy);
  82. }
  83. public static ServicePoint FindServicePoint (Uri address, IWebProxy proxy)
  84. {
  85. if (address == null)
  86. throw new ArgumentNullException ("address");
  87. // if ()
  88. // throw new InvalidOperationException ("maximum number of service points reached");
  89. throw new NotImplementedException ();
  90. }
  91. }
  92. }