   Socket Reading & Select
  I've defined my socket to be non-blocking.  I want to monitor the socket and read when data is available.  I could use the ioctlsocket (windows socket) and constantly loop to check for data.  I tried to use the select call w/ a timeout to wait for data?FD_ZERO(&ReadSet);FD_SET(MySocket, &ReadSet);select(1, &ReadSet, NULL, NULL, &TimeOut);However, it always came back immediately to indicate activity.  Is it just checking for readability and NOT data available for read??  My intention was to have a socket reading thread.
Quote:Original post by fathom88FD_ZERO(&ReadSet);FD_SET(MySocket, &ReadSet);select(1, &ReadSet, NULL, NULL, &TimeOut);The first argument to select() is likely incorrect.  Try passing MySocket+1 instead.   ;  I thought the value was ignored under Windows.  I'll give it a try.   ;  First of all, the first argument to select() is supposed to be the highest file descriptor you are interested in, plus one. So in your case it should be MySocket+1.Once select returns, you have to check the return value for errors. It will return -1 on an error (for instance, it could be that passing in the wrong first argument is an error?). Then you can check errno to find out what was wrong. This is a must for any networking code, not only for the call to select, so get used to it even if it is a little tedious.You should use FD_ISSET to see what events have been triggered (even though you currently only have one event).Hope that helps.   ;  Tried it.  I checked the return value and it's a one which indicates the checked condition was met.   ;  What happens when you try to read from the socket? If select is telling you that there is something to be read, this is probably the case.I think you may have to post a complete program (keep it as short as possible) that shows the problem.Disclaimer: I've only ever done network programming on Unix, so it could be that you are hitting some obscure corner of Windows and I won't be able to help.   ;  It will return immediately if the socket is closed, isset will return true but read will return 0.   