[Bug libgcj/11836] New: Socket.connect with a timeout of non-zero always times out.

gladish at spinnakernet dot com gcc-bugzilla@gcc.gnu.org
Wed Aug 6 17:34:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11836

           Summary: Socket.connect with a timeout of non-zero always times
                    out.
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libgcj
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gladish at spinnakernet dot com
                CC: gcc-bugs at gcc dot gnu dot org

The following code snipped always times out.

InetAddress address = InetAddress.getByName( "gcc.gnu.org" );
InetSocketAddress addr = new InetSocketAddress( address, 80 );
Socket s = new Socket();
s.connect( addr, 4000 );

I added the write file descriptor set to the select calls and that seemed to fix
it. 

335c335
<       fd_set rset;
---
>       fd_set rset, wset;
338a339
>       wset = rset;
343c344
<       if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
---
>       if ((retval = _Jv_select (fnum + 1, &rset, &wset, NULL, &tv)) < 0)
347a349,352
>
>       // restore socket state back to original. we dont' want to leave it in
>       // non-blocking mode.
>       ::fcntl (fnum, F_SETFL, flags );
367a373
>
397c403
<       fd_set rset;
---
>       fd_set rset, wset;
400a407
>       wset = rset;
404c411
<       if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
---
>       if ((retval = _Jv_select (fnum + 1, &rset, &wset, NULL, &tv)) < 0)
556c563
<       fd_set read_fds;
---
>       fd_set read_fds, write_fds;
558a566
>       write_fds = read_fds;
565c573
<         _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
---
>         _Jv_select (fnum + 1, &read_fds, &write_fds, NULL, &timeout_value);
622c630
<       fd_set read_fds;
---
>       fd_set read_fds, write_fds;
624a633
>       write_fds = read_fds;
631c640
<         _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
---
>         _Jv_select (fnum + 1, &read_fds, &write_fds, NULL, &timeout_value);
713c722
<         fd_set rd;
---
>         fd_set rd, wd;
715a725
>       wd = rd;
719c729
<         r = _Jv_select (fnum + 1, &rd, NULL, NULL, &tv);
---
>         r = _Jv_select (fnum + 1, &rd, &wd, NULL, &tv);


The socket is also put back into a block state so reads/writes don't perform
unexpectedly.

NOTE: I have also patched the Socket.java class to the most recent under CVS
(1.9.6.10)
 
Distro: Red Hat Linux 7.3 2.96-112
Kernel: Linux version 2.4.18-19.7.x (i686)



More information about the Gcc-bugs mailing list