[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible fix for tcp-connect under Linux 2.4



Quoting "John R. Hall":
> I traced the tcp-connect failure to the following code (in network.c,
> tcp_connect):
> 
> #ifdef USE_UNIX_SOCKETS_TCP
>             status = recv(s, NULL, 0, 0); /* test input */
>             if (!status)
>               status = send(s, NULL, 0, 0); /* test output */

Aha - so the problem had nothing to do with connect(). I was looking in
the wrong place.

> I'm guessing this is just intended as an extra sanity check, but I
> suspect that zero-byte network operations are open to interpretation,
> especially when it comes to detecting the zero-size situation and not
> trying to queue a send or receive.

I took this from the first suggestion in the sockets FAQ:

  If the connection fails:
    the socket will select as readable *and* writable, but either a
    read or write will return the error code from the connection
    attempt. 

Guess we should use the second suggestion, instead...:

    Also, you can use getsockopt(SO_ERROR) to get the error status -
    but be careful; some systems return the error code in the result
    parameter of getsockopt(), but others (incorrectly) cause the
    getsockopt call itself to fail with the stored value as the error.

Thanks for tracking this down.

Matthew