WebConnectionGroup.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. IPAddress address;
  18. ArrayList connections;
  19. public WebConnectionGroup (ServicePoint sPoint, string name, IPAddress address)
  20. {
  21. this.sPoint = sPoint;
  22. this.name = name;
  23. this.address = address;
  24. connections = new ArrayList (1);
  25. }
  26. public WebConnection GetConnection (string name)
  27. {
  28. WebConnection cnc = null;
  29. lock (connections) {
  30. WeakReference cncRef = null;
  31. // Remove disposed connections
  32. int end = connections.Count;
  33. ArrayList removed = null;
  34. for (int i = 0; i < end; i++) {
  35. cncRef = (WeakReference) connections [i];
  36. cnc = cncRef.Target as WebConnection;
  37. if (cnc == null) {
  38. if (removed == null)
  39. removed = new ArrayList (1);
  40. removed.Add (i);
  41. }
  42. }
  43. if (removed != null) {
  44. for (int i = removed.Count - 1; i >= 0; i--)
  45. connections.RemoveAt ((int) removed [i]);
  46. }
  47. //TODO: Should use the limits in the config file.
  48. if (connections.Count == 0) {
  49. cnc = new WebConnection (this, sPoint);
  50. connections.Add (new WeakReference (cnc));
  51. } else {
  52. cncRef = (WeakReference) connections [connections.Count - 1];
  53. cnc = cncRef.Target as WebConnection;
  54. }
  55. }
  56. return cnc;
  57. }
  58. public string Name {
  59. get { return name; }
  60. }
  61. }
  62. }