Posted on 2004-08-21
I have a fairly simple Windows TCP/IP client that I am creating. Everything seems to work except trying to call select() to check and see if data is ready for reading on my socket. I'm just using a standard socket with the non-blocking flag set set and the following code:
tv.tv_sec = timeout;
int err = 0;
err = select(0, &set, (fd_set*)NULL, (fd_set*)NULL, &tv);
err = select(0, (fd_set*)NULL, &set, (fd_set*)NULL, &tv);
err = select(0, (fd_set*)NULL, (fd_set*)NULL, &set, &tv);
if((err == 0) || (err == SOCKET_ERROR))
return FD_ISSET(connection, &set);
When I call the above function, it ALWAYS returns true. When I step through the code, err is set to ERROR_SUCCCESS and FD_ISSSET returns nonzero, even if there is no data on the socket to be read.
I am not stuck using the above solution. Any way that you can suggest to find out if the socket is ready for reading would be fine as long as it doesn not use asynchronous sockets.