I'm currently struggling to implement a decent version of select() system call for my OS. I have read some pages from The Single UNIX Specification (http://pubs.opengroup.org/onlinepubs/00 ... elect.html and http://pubs.opengroup.org/onlinepubs/00 ... elect.html) as well the manual pages from my Linux distribution but there are still shades of grey concerning sockets. In fact, up to now, I have only implemented TCP sockets, so here, "socket" will mean "TCP socket".
Let's consider for instance the following statement:
But what does "to be ready to read" mean for a socket? At first, I thought it meant the socket had data in its receive buffer. However, after experimenting a bit, it appeared to me that it was not so simple. Indeed, after the connection is closed by the remote host, executing select() on the local host returns 1 and says the socket is ready for read, since the socket file descriptor is still set in the readfds set after select() returns. It seems quite strange to me, and I could not find any explanation neither in the Single UNIX Specification nor in the Linux manual (but maybe I didn't look at the right place).If the readfds argument is not a null pointer, it points to an object of type fd_set that on input specifies the file descriptors to be checked for being ready to read, and on output indicates which file descriptors are ready to read.
Could you please help me if you have experienced troubles implementing select() or if you have more complete doc. ?
Thanks in advance.