Author: dick
Date: 2007-08-08 09:14:21 -0400 (Wed, 08 Aug 2007)
New Revision: 83666
Modified:
trunk/mcs/class/System/System.Net/ChangeLog
trunk/mcs/class/System/System.Net/FtpWebRequest.cs
trunk/mcs/class/System/System.Net/ServicePoint.cs
trunk/mcs/class/System/System.Net/WebConnection.cs
trunk/mcs/class/System/Test/System.Net/ChangeLog
trunk/mcs/class/System/Test/System.Net/ServicePointTest.cs
Log:
2007-06-28 Chris Howie <[EMAIL PROTECTED]>
* ServicePoint.cs: Implemented BindIPEndPointDelegate.
* FtpWebRequest.cs: Respect ServicePoint.BindIPEndPointDelegate.
* WebConnection.cs: Respect ServicePoint.BindIPEndPointDelegate.
2007-06-28 Chris Howie <[EMAIL PROTECTED]>
* ServicePointTest.cs: Add some loose tests for
ServicePoint.BindIPEndPointDelegate.
Modified: trunk/mcs/class/System/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Net/ChangeLog 2007-08-08 12:56:29 UTC (rev
83665)
+++ trunk/mcs/class/System/System.Net/ChangeLog 2007-08-08 13:14:21 UTC (rev
83666)
@@ -1,3 +1,9 @@
+2007-06-28 Chris Howie <[EMAIL PROTECTED]>
+
+ * ServicePoint.cs: Implemented BindIPEndPointDelegate.
+ * FtpWebRequest.cs: Respect ServicePoint.BindIPEndPointDelegate.
+ * WebConnection.cs: Respect ServicePoint.BindIPEndPointDelegate.
+
2007-08-08 Jb Evain <[EMAIL PROTECTED]>
* HttpWebRequest.cs: .ctor(Uri) is public in 2.1.
Modified: trunk/mcs/class/System/System.Net/FtpWebRequest.cs
===================================================================
--- trunk/mcs/class/System/System.Net/FtpWebRequest.cs 2007-08-08 12:56:29 UTC
(rev 83665)
+++ trunk/mcs/class/System/System.Net/FtpWebRequest.cs 2007-08-08 13:14:21 UTC
(rev 83666)
@@ -699,13 +699,21 @@
Socket sock = null;
foreach (IPAddress address in hostEntry.AddressList) {
sock = new Socket (address.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
- try {
- sock.Connect (new IPEndPoint (address,
requestUri.Port));
- localEndPoint = (IPEndPoint)
sock.LocalEndPoint;
- break;
- } catch (SocketException) {
+
+ IPEndPoint remote = new IPEndPoint (address,
requestUri.Port);
+
+ if (!ServicePoint.CallEndPointDelegate (sock,
remote)) {
sock.Close ();
sock = null;
+ } else {
+ try {
+ sock.Connect (remote);
+ localEndPoint = (IPEndPoint)
sock.LocalEndPoint;
+ break;
+ } catch (SocketException) {
+ sock.Close ();
+ sock = null;
+ }
}
}
Modified: trunk/mcs/class/System/System.Net/ServicePoint.cs
===================================================================
--- trunk/mcs/class/System/System.Net/ServicePoint.cs 2007-08-08 12:56:29 UTC
(rev 83665)
+++ trunk/mcs/class/System/System.Net/ServicePoint.cs 2007-08-08 13:14:21 UTC
(rev 83666)
@@ -58,6 +58,9 @@
#if NET_1_1
bool useNagle;
#endif
+#if NET_2_0
+ BindIPEndPoint endPointCallback = null;
+#endif
// Constructors
@@ -82,15 +85,10 @@
return new NotImplementedException ();
}
- [MonoTODO]
public BindIPEndPoint BindIPEndPointDelegate
{
- get {
- throw GetMustImplement ();
- }
- set {
- throw GetMustImplement ();
- }
+ get { return endPointCallback; }
+ set { endPointCallback = value; }
}
#endif
@@ -328,6 +326,44 @@
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
}
}
Modified: trunk/mcs/class/System/System.Net/WebConnection.cs
===================================================================
--- trunk/mcs/class/System/System.Net/WebConnection.cs 2007-08-08 12:56:29 UTC
(rev 83665)
+++ trunk/mcs/class/System/System.Net/WebConnection.cs 2007-08-08 13:14:21 UTC
(rev 83666)
@@ -121,18 +121,31 @@
foreach (IPAddress address in
hostEntry.AddressList) {
socket = new Socket
(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
- try {
- socket.Connect (new
IPEndPoint(address, sPoint.Address.Port));
- status =
WebExceptionStatus.Success;
- break;
- } catch (SocketException) {
- // This might be null if the
request is aborted
- if (socket != null) {
- socket.Close();
- socket = null;
- status =
WebExceptionStatus.ConnectFailure;
+
+ IPEndPoint remote = new IPEndPoint
(address, sPoint.Address.Port);
+
+#if NET_2_0
+ if (!sPoint.CallEndPointDelegate
(socket, remote)) {
+ socket.Close ();
+ socket = null;
+ status =
WebExceptionStatus.ConnectFailure;
+ } else {
+#endif
+ try {
+ socket.Connect (remote);
+ status =
WebExceptionStatus.Success;
+ break;
+ } catch (SocketException) {
+ // This might be null
if the request is aborted
+ if (socket != null) {
+ socket.Close ();
+ socket = null;
+ status =
WebExceptionStatus.ConnectFailure;
+ }
}
+#if NET_2_0
}
+#endif
}
}
}
Modified: trunk/mcs/class/System/Test/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.Net/ChangeLog 2007-08-08 12:56:29 UTC
(rev 83665)
+++ trunk/mcs/class/System/Test/System.Net/ChangeLog 2007-08-08 13:14:21 UTC
(rev 83666)
@@ -1,3 +1,8 @@
+2007-06-28 Chris Howie <[EMAIL PROTECTED]>
+
+ * ServicePointTest.cs: Add some loose tests for
+ ServicePoint.BindIPEndPointDelegate.
+
2007-08-01 Rodrigo Kumpera <[EMAIL PROTECTED]>
* HttpListener2Test.cs: Fixed Cookie Test
Modified: trunk/mcs/class/System/Test/System.Net/ServicePointTest.cs
===================================================================
--- trunk/mcs/class/System/Test/System.Net/ServicePointTest.cs 2007-08-08
12:56:29 UTC (rev 83665)
+++ trunk/mcs/class/System/Test/System.Net/ServicePointTest.cs 2007-08-08
13:14:21 UTC (rev 83666)
@@ -152,6 +152,46 @@
}
}
+#if NET_2_0
+ [Test]
+ [Category ("InetAccess")]
+#if TARGET_JVM
+ [Ignore ("The System.Net.ServicePointManager.FindServicePoint(Uri) is
not supported")]
+#endif
+ public void EndPointBind ()
+ {
+ Uri uri = new Uri ("http://www.go-mono.com/");
+ ServicePoint sp = ServicePointManager.FindServicePoint (uri);
+
+ HttpWebRequest req = (HttpWebRequest) WebRequest.Create (uri);
+
+ bool called = false;
+
+ sp.BindIPEndPointDelegate = delegate {
+ Assertion.Assert(!called);
+ called = true;
+ return null;
+ };
+
+ req.GetResponse ().Close ();
+
+ Assertion.Assert (called);
+
+ req = (HttpWebRequest) WebRequest.Create (uri);
+ called = false;
+
+ sp.BindIPEndPointDelegate = delegate(ServicePoint point,
IPEndPoint remote, int times) {
+ Assertion.Assert(times < 5);
+ called = true;
+ return new IPEndPoint(IPAddress.Parse("0.0.0.0"), 12345
+ times);
+ };
+
+ req.GetResponse ().Close ();
+
+ Assertion.Assert(called);
+ }
+#endif
+
// Debug code not used now, but could be useful later
/*
private void WriteServicePoint (string label, ServicePoint sp)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches