| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- //
- // System.Net.WebConnectionGroup
- //
- // Authors:
- // Gonzalo Paniagua Javier ([email protected])
- //
- // (C) 2003 Ximian, Inc (http://www.ximian.com)
- //
- using System.Collections;
- using System.Net.Sockets;
- namespace System.Net
- {
- class WebConnectionGroup
- {
- ServicePoint sPoint;
- string name;
- IPAddress address;
- ArrayList connections;
- public WebConnectionGroup (ServicePoint sPoint, string name, IPAddress address)
- {
- this.sPoint = sPoint;
- this.name = name;
- this.address = address;
- connections = new ArrayList (1);
- }
- public WebConnection GetConnection (string name)
- {
- WebConnection cnc = null;
- lock (connections) {
- WeakReference cncRef = null;
- // Remove disposed connections
- int end = connections.Count;
- ArrayList removed = null;
- for (int i = 0; i < end; i++) {
- cncRef = (WeakReference) connections [i];
- cnc = cncRef.Target as WebConnection;
- if (cnc == null) {
- if (removed == null)
- removed = new ArrayList (1);
- removed.Add (i);
- }
- }
- if (removed != null) {
- for (int i = removed.Count - 1; i >= 0; i--)
- connections.RemoveAt ((int) removed [i]);
- }
- //TODO: Should use the limits in the config file.
- if (connections.Count == 0) {
- cnc = new WebConnection (this, sPoint);
- connections.Add (new WeakReference (cnc));
- } else {
- cncRef = (WeakReference) connections [connections.Count - 1];
- cnc = cncRef.Target as WebConnection;
- }
- }
- return cnc;
- }
- public string Name {
- get { return name; }
- }
-
- }
- }
|