ServicePoint.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // System.Net.ServicePoint
  3. //
  4. // Author:
  5. // Lawrence Pit ([email protected])
  6. //
  7. using System;
  8. using System.Security.Cryptography.X509Certificates;
  9. using System.Threading;
  10. namespace System.Net
  11. {
  12. public class ServicePoint
  13. {
  14. private Uri uri;
  15. private int connectionLimit;
  16. private int maxIdleTime;
  17. private int currentConnections;
  18. private DateTime idleSince;
  19. private Version protocolVersion;
  20. // Constructors
  21. internal ServicePoint (Uri uri, int connectionLimit, int maxIdleTime)
  22. {
  23. this.uri = uri;
  24. this.connectionLimit = connectionLimit;
  25. this.maxIdleTime = maxIdleTime;
  26. this.currentConnections = 0;
  27. this.idleSince = DateTime.Now;
  28. }
  29. // Properties
  30. public Uri Address {
  31. get { return this.uri; }
  32. }
  33. [MonoTODO]
  34. public X509Certificate Certificate {
  35. get { throw new NotImplementedException (); }
  36. }
  37. [MonoTODO]
  38. public X509Certificate ClientCertificate {
  39. get { throw new NotImplementedException (); }
  40. }
  41. public int ConnectionLimit {
  42. get { return connectionLimit; }
  43. set {
  44. if (value <= 0)
  45. throw new ArgumentOutOfRangeException ();
  46. connectionLimit = value;
  47. }
  48. }
  49. public string ConnectionName {
  50. get { return uri.Scheme; }
  51. }
  52. public int CurrentConnections {
  53. get { return currentConnections; }
  54. }
  55. public DateTime IdleSince {
  56. get { return idleSince; }
  57. }
  58. public int MaxIdleTime {
  59. get { return maxIdleTime; }
  60. set {
  61. if (value < Timeout.Infinite || value > Int32.MaxValue)
  62. throw new ArgumentOutOfRangeException ();
  63. this.maxIdleTime = value;
  64. }
  65. }
  66. public virtual Version ProtocolVersion {
  67. get { return protocolVersion; }
  68. }
  69. public bool SupportsPipelining {
  70. get { return HttpVersion.Version11.Equals (protocolVersion); }
  71. }
  72. // Methods
  73. public override int GetHashCode()
  74. {
  75. return base.GetHashCode ();
  76. }
  77. // Internal Methods
  78. internal bool AvailableForRecycling {
  79. get {
  80. return CurrentConnections == 0
  81. && maxIdleTime != Timeout.Infinite
  82. && DateTime.Now >= IdleSince.AddMilliseconds (maxIdleTime);
  83. }
  84. }
  85. }
  86. }