Patch: fix non-blocking socket connect
Anthony Green
green@redhat.com
Wed Dec 28 18:39:00 GMT 2005
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. I'll file
a PR about the weird non-blocking stuff later today.
Thanks,
AG
2005-12-28 Anthony Green <green@redhat.com>
* gnu/java/net/natPlainSocketImplPosix.cc (connect): Record
address and port before attempting anything.
Index: gnu/java/net/natPlainSocketImplPosix.cc
===================================================================
--- gnu/java/net/natPlainSocketImplPosix.cc (revision 109114)
+++ gnu/java/net/natPlainSocketImplPosix.cc (working copy)
@@ -142,6 +142,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;
@@ -197,9 +206,6 @@
goto error;
}
- 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