Patch: fix non-blocking socket connect

Anthony Green green@redhat.com
Wed Dec 28 18:49:00 GMT 2005


On Wed, 2005-12-28 at 10:39 -0800, Anthony Green wrote:
> On Tue, 2005-12-27 at 13:58 -0700, Tom Tromey wrote:
> > Yeah, for this case I think your patch is right. 
> 
> Ok, this is the patch I committed to HEAD and the 4.1 branch.  

And I've just checked in this for HEAD and 4.1 for the Win32 side of
things.

2005-12-28  Anthony Green  <green@redhat.com>

	* gnu/java/net/natPlainSocketImplWin32.cc (connect): Same 
	as previous patch, but for win32.

 
Index: gnu/java/net/natPlainSocketImplWin32.cc
===================================================================
--- gnu/java/net/natPlainSocketImplWin32.cc	(revision 109116)
+++ gnu/java/net/natPlainSocketImplWin32.cc	(working copy)
@@ -133,6 +133,15 @@
   ::java::net::InetAddress *host = tmp->getAddress();
   jint rport = tmp->getPort();
 
+  // Set the SocketImpl's address and port fields before we try to
+  // connect.  Note that the fact that these are set doesn't imply
+  // that we're actually connected to anything.  We need to record
+  // this data before we attempt the connect, since non-blocking
+  // SocketChannels will use this and almost certainly throw timeout
+  // exceptions.
+  address = host;
+  port = rport;
+
   union SockAddr u;
   socklen_t addrlen = sizeof(u);
   jbyteArray haddress = host->addr;
@@ -208,9 +217,6 @@
         throwConnectException();
     }
 
-  address = host;
-  port = rport;
-
   // A bind may not have been done on this socket; if so, set localport now.
   if (localport == 0)
     {




More information about the Java-patches mailing list