select()
Todd M. Grimm
grimm@itd.nrl.navy.mil
Sun Oct 11 08:54:00 GMT 1998
Thanks to all those who responded to my select() problems. I have found my
solution. Maybe this is what ails some of you with similar problems,
maybe your problem is something different.
To recap, my receiving process was hanging on select() at the start even
though there was data. When a key (even shift) was pressed in the shell
window it would unhang and consume the already waiting data. The other
problem was that all calls to select() after that returned with a value
of 1 even when there was no data on the socket.
It turns out that at run-time or maybe at link time, the select() that is
used is the unix kind that that uses the bit mask to specify what file
descriptors are being watched. However, the include files I was using use
some kind of Windows version that uses a structure with an array in it.
So, when the bitmask version tried to use the structure I was passing it,
it looked like a bitmask that wanted it to check stdin all the time. This
explains the bad behavior. The solution is to simple use the right
include files with the bitmask macros (FD_SET, FD_ZERO, etc.). That way
what I build and pass really is the bitmask and it works just fine.
These are those simple little platform issues that really bite you good.
I hope this helps someone else avoid the watsed hours this cost me.
Attached are my simple demo programs that do it right now. These may be
useful to someone looking for a starting point or to see what they do for
includes that works.
Todd
More information about the Cygwin
mailing list