WebConnectionGroup.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // System.Net.WebConnectionGroup
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System.Collections;
  10. using System.Net.Sockets;
  11. namespace System.Net
  12. {
  13. class WebConnectionGroup
  14. {
  15. ServicePoint sPoint;
  16. string name;
  17. ArrayList connections;
  18. public WebConnectionGroup (ServicePoint sPoint, string name)
  19. {
  20. this.sPoint = sPoint;
  21. this.name = name;
  22. connections = new ArrayList (1);
  23. }
  24. public WebConnection GetConnection (string name)
  25. {
  26. WebConnection cnc = null;
  27. lock (connections) {
  28. WeakReference cncRef = null;
  29. // Remove disposed connections
  30. int end = connections.Count;
  31. ArrayList removed = null;
  32. for (int i = 0; i < end; i++) {
  33. cncRef = (WeakReference) connections [i];
  34. cnc = cncRef.Target as WebConnection;
  35. if (cnc == null) {
  36. if (removed == null)
  37. removed = new ArrayList (1);
  38. removed.Add (i);
  39. }
  40. }
  41. if (removed != null) {
  42. for (int i = removed.Count - 1; i >= 0; i--)
  43. connections.RemoveAt ((int) removed [i]);
  44. }
  45. //TODO: Should use the limits in the config file.
  46. if (connections.Count == 0) {
  47. cnc = new WebConnection (this, sPoint);
  48. connections.Add (new WeakReference (cnc));
  49. } else {
  50. cncRef = (WeakReference) connections [connections.Count - 1];
  51. cnc = cncRef.Target as WebConnection;
  52. }
  53. }
  54. return cnc;
  55. }
  56. public string Name {
  57. get { return name; }
  58. }
  59. }
  60. }