I have 2 ‘Select‘ calls one after other on same fd. both have diff fd_set, but both have only one fd int it and the same fd.(trying to read from the same socket)
the problem is second Select times out.
I am trying to recreate the issue but cant, in my testing the second select goes through almost instantaneously, even with timeout=0.
I am confused. Does the Socket have data in Kernel Space due to which the second select goes through immediately.
Yes, the socket does have incoming data buffered in kernel space – that’s what you’ll get when you call
read(), after the firstselect()returns to indicate that there is something available to read. If you haven’t read it all yet, then of course anotherselect()will return immediately.If you have called
read(), then it probably indicates that there’s more data available than you’ve read, and you should carry on reading until you’ve got it all. There’s only a problem here if either the call toread()fails or blocks afterselecthas indicated that it’s readable, or if you have reason to believe that there should be no data following what you’ve already read.