kernel 2.4.18 - select() returning strange value

Jacob Cohen (cohen@rafb.net)
Fri, 7 Jun 2002 13:09:05 -0700


Hello everyone.

Please CC: me on replies

Summary: when calling select() on a set of file descriptors containing
only the descriptor of a non-connected stream socket, select() returns
1 and marks the FD set as if data were waiting on the socket.

Details: I first noticed, when trying to install the perl module
Net::Telnet, that the select test was failing. Running strace on the
test program, I determined that select() was returning an unexpected
value.
I wrote a simple C program to duplicate this behavior, and got the
same results.

sock = socket(AF_INET, SOCK_STREAM, 6);
FD_ZERO(&rfds);
FD_SET(sock, &rfds);
tv.tv_sec = 0; tv.tv_usec = 0;
retval = select(sock+1, &rfds, NULL, NULL, &tv);

Produced these strace lines:

socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
select(4, [3], NULL, NULL, {0, 0}) = 1 (in [3], left {0, 0})

According to what I've read in the man pages for select() and
socket(), a nonconnected socket should be unreadable, and therefore
select() should timeout and return 0. I cannot figure out why it is
returning 1.

I've gotten this result on kernel 2.4.18, and someone confirmed the
same result on 2.4.19-pre7. A user with 2.2.19 ran my test program and
got a return value of 0, which is what I would expect the return value
to be.

Has something changed in the kernel or the way the select() syscall
behaves on a nonconnected socket that I should be aware of? I cannot
find anything relevant in the recent change logs, but I am probably
missing something.

Any insight into this would be much appreciated. Thanks in advance.

-- 
Regards,
Jake                          mailto:cohen@rafb.net

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/