2008-11-04 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mcs / class / System / System.Net / ServicePoint.cs
index 9ffbf85d99ad303fba2bbc5025b48227304c233d..f9bc2a7f148acaecabc39d65884e50fec3b11a12 100644 (file)
@@ -54,9 +54,13 @@ namespace System.Net
                bool sendContinue = true;
                bool useConnect;
                object locker = new object ();
+               object hostE = new object ();
 #if NET_1_1
                bool useNagle;
 #endif
+#if NET_2_0
+               BindIPEndPoint endPointCallback = null;
+#endif
                
                // Constructors
 
@@ -74,6 +78,19 @@ namespace System.Net
                public Uri Address {
                        get { return uri; }
                }
+
+#if NET_2_0
+               static Exception GetMustImplement ()
+               {
+                       return new NotImplementedException ();
+               }
+
+               public BindIPEndPoint BindIPEndPointDelegate
+               {
+                       get { return endPointCallback; }
+                       set { endPointCallback = value; }
+               }
+#endif
                
                public X509Certificate Certificate {
                        get { return certificate; }
@@ -82,6 +99,19 @@ namespace System.Net
                public X509Certificate ClientCertificate {
                        get { return clientCertificate; }
                }
+
+#if NET_2_0
+               [MonoTODO]
+               public int ConnectionLeaseTimeout
+               {
+                       get {
+                               throw GetMustImplement ();
+                       }
+                       set {
+                               throw GetMustImplement ();
+                       }
+               }
+#endif
                
                public int ConnectionLimit {
                        get { return connectionLimit; }
@@ -99,17 +129,17 @@ namespace System.Net
 
                public int CurrentConnections {
                        get {
-                               lock (locker) {
-                                       return currentConnections;
-                               }
+                               return currentConnections;
                        }
                }
 
                public DateTime IdleSince {
                        get {
-                               lock (locker) {
-                                       return idleSince;
-                               }
+                               return idleSince;
+                       }
+                       internal set {
+                               lock (locker)
+                                       idleSince = value;
                        }
                }
                
@@ -125,6 +155,19 @@ namespace System.Net
                public virtual Version ProtocolVersion {
                        get { return protocolVersion; }
                }
+
+#if NET_2_0
+               [MonoTODO]
+               public int ReceiveBufferSize
+               {
+                       get {
+                               throw GetMustImplement ();
+                       }
+                       set {
+                               throw GetMustImplement ();
+                       }
+               }
+#endif
                
                public bool SupportsPipelining {
                        get { return HttpVersion.Version11.Equals (protocolVersion); }
@@ -150,10 +193,12 @@ namespace System.Net
                }
                // Methods
                
+#if !NET_2_0
                public override int GetHashCode() 
                {
                        return base.GetHashCode ();
                }
+#endif
                
                // Internal Methods
 
@@ -187,7 +232,10 @@ namespace System.Net
                internal IPHostEntry HostEntry
                {
                        get {
-                               if (host == null) {
+                               lock (hostE) {
+                                       if (host != null)
+                                               return host;
+
                                        string uriHost = uri.Host;
 
                                        // There is no need to do DNS resolution on literal IP addresses
@@ -223,7 +271,7 @@ namespace System.Net
                {
                        protocolVersion = version;
                }
-               
+#if !TARGET_JVM && !NET_2_1
                WebConnectionGroup GetConnectionGroup (string name)
                {
                        if (name == null)
@@ -244,11 +292,19 @@ namespace System.Net
                        
                        lock (locker) {
                                WebConnectionGroup cncGroup = GetConnectionGroup (groupName);
-                               cnc = cncGroup.GetConnection ();
+                               cnc = cncGroup.GetConnection (request);
                        }
                        
                        return cnc.SendRequest (request);
                }
+#endif
+#if NET_2_0
+               [MonoNotSupported ("")]
+               public bool CloseConnectionGroup (string connectionGroupName)
+               {
+                       throw new NotImplementedException ();
+               }
+#endif
 
                internal void IncrementConnection ()
                {
@@ -272,6 +328,45 @@ namespace System.Net
                        certificate = server;
                        clientCertificate = client;
                }
+
+#if NET_2_0
+               internal bool CallEndPointDelegate (Socket sock, IPEndPoint remote)
+               {
+                       if (endPointCallback == null)
+                               return true;
+
+                       int count = 0;
+                       for (;;) {
+                               IPEndPoint local = null;
+                               try {
+                                       local = endPointCallback (this,
+                                               remote, count);
+                               } catch {
+                                       // This is to differentiate from an
+                                       // OverflowException, which should propagate.
+                                       return false;
+                               }
+
+                               if (local == null)
+                                       return true;
+
+                               try {
+                                       sock.Bind (local);
+                               } catch (SocketException) {
+                                       // This is intentional; the docs say
+                                       // that if the Bind fails, we keep
+                                       // going until there is an
+                                       // OverflowException on the retry
+                                       // count.
+                                       checked { ++count; }
+                                       continue;
+                               }
+
+                               return true;
+                       }
+               }
+#endif
        }
 }
 
+