This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
java.net.Socket.connect always times out with connection timeoutof non-zero
- From: Jacob Gladish <gladish at spinnakernet dot com>
- To: gcc-patches at gcc dot gnu dot org, java-patches at gcc dot gnu dot org
- Date: 06 Aug 2003 16:22:29 -0400
- Subject: java.net.Socket.connect always times out with connection timeoutof non-zero
- Organization: Spinnaker Networks
I found, what I believe is a problem in the java.net.Socket class where
the connect() method always times out when passing in a timeout value of
anything greater than zero. I applied the following change to the
natPlaingSocketImpl.cc class, and it appears to be working fine now.
*** 332,350 ****
if ((_Jv_connect (fnum, ptr, len) != 0) && (errno !=
EINPROGRESS))
goto error;
! fd_set rset;
struct timeval tv;
FD_ZERO(&rset);
FD_SET(fnum, &rset);
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;
int retval;
! if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) <
0)
goto error;
else if (retval == 0)
throw new java::net::SocketTimeoutException
(JvNewStringUTF ("Connect timed out"));
}
else
#endif
--- 332,354 ----
if ((_Jv_connect (fnum, ptr, len) != 0) && (errno !=
EINPROGRESS))
goto error;
! fd_set rset, wset;
struct timeval tv;
FD_ZERO(&rset);
FD_SET(fnum, &rset);
+ wset = rset;
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;
int retval;
! if ((retval = _Jv_select (fnum + 1, &rset, &wset, NULL, &tv)) <
0)
goto error;
else if (retval == 0)
throw new java::net::SocketTimeoutException
(JvNewStringUTF ("Connect timed out"));
+
+ // set the socket back into a blocking state
+ ::fcntl (fnum, F_SETFL, flags);
Can anyone confirm the legitamcy of this change on other platforms? I'm
using:
linux 2.4.18-19.7.x on i686. (It's a redhat 7.1 install)
thanks
jake