Flush (work in progress)
[mono.git] / mcs / class / System / System.Net / ServicePoint.cs
index 956998e112b07201e62dea33dbd00c269277f163..c93f36d1bba52b5c28f89ab5f537dc4b602af70c 100644 (file)
@@ -58,6 +58,9 @@ namespace System.Net
 #if NET_1_1
                bool useNagle;
 #endif
+#if NET_2_0
+               BindIPEndPoint endPointCallback = null;
+#endif
                
                // Constructors
 
@@ -75,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; }
@@ -83,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; }
@@ -100,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;
                        }
                }
                
@@ -126,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); }
@@ -137,7 +179,6 @@ namespace System.Net
                        set { SendContinue = value; }
                }
 
-               [MonoTODO ("Use me")]
                public bool UseNagleAlgorithm {
                        get { return useNagle; }
                        set { useNagle = value; }
@@ -151,10 +192,12 @@ namespace System.Net
                }
                // Methods
                
+#if !NET_2_0
                public override int GetHashCode() 
                {
                        return base.GetHashCode ();
                }
+#endif
                
                // Internal Methods
 
@@ -227,7 +270,8 @@ namespace System.Net
                {
                        protocolVersion = version;
                }
-               
+
+#if !TARGET_JVM
                WebConnectionGroup GetConnectionGroup (string name)
                {
                        if (name == null)
@@ -248,11 +292,26 @@ 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
+               public bool CloseConnectionGroup (string connectionGroupName)
+               {
+                       lock (locker) {
+                               WebConnectionGroup cncGroup = GetConnectionGroup (connectionGroupName);
+                               if (cncGroup != null) {
+                                       cncGroup.Close ();
+                                       return true;
+                               }
+                       }
+
+                       return false;
+               }
+#endif
 
                internal void IncrementConnection ()
                {
@@ -276,6 +335,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
        }
 }
 
+