Flush (work in progress)
[mono.git] / mcs / class / System / System.Net / ServicePoint.cs
index d8bcf827077b693c8236143802b686366aaf45c7..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
 
@@ -82,15 +85,10 @@ namespace System.Net
                        return new NotImplementedException ();
                }
 
-               [MonoTODO]
                public BindIPEndPoint BindIPEndPointDelegate
                {
-                       get {
-                               throw GetMustImplement ();
-                       }
-                       set {
-                               throw GetMustImplement ();
-                       }
+                       get { return endPointCallback; }
+                       set { endPointCallback = value; }
                }
 #endif
                
@@ -181,7 +179,6 @@ namespace System.Net
                        set { SendContinue = value; }
                }
 
-               [MonoTODO ("Use me")]
                public bool UseNagleAlgorithm {
                        get { return useNagle; }
                        set { useNagle = value; }
@@ -195,10 +192,12 @@ namespace System.Net
                }
                // Methods
                
+#if !NET_2_0
                public override int GetHashCode() 
                {
                        return base.GetHashCode ();
                }
+#endif
                
                // Internal Methods
 
@@ -271,6 +270,7 @@ namespace System.Net
                {
                        protocolVersion = version;
                }
+
 #if !TARGET_JVM
                WebConnectionGroup GetConnectionGroup (string name)
                {
@@ -292,17 +292,24 @@ 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 ();
+                       lock (locker) {
+                               WebConnectionGroup cncGroup = GetConnectionGroup (connectionGroupName);
+                               if (cncGroup != null) {
+                                       cncGroup.Close ();
+                                       return true;
+                               }
+                       }
+
+                       return false;
                }
 #endif
 
@@ -328,6 +335,44 @@ 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
        }
 }