Re: reading from multiple ports
From: firstname.lastname@example.org Date: Wed, 23 Apr 2003 14:09:10 GMT
Valentin Nechayev <email@example.com> writes:
> >>> David Schwartz wrote:
> > >> I've set the sockets in non-blocking mode.It recognizes that the new
> >> If you're using select() why do you need non-blocking sockets? Just
> >> don't read from them if FD_ISSET is false for that descriptor.
> DS> Select should always be used with non-blocking sockets. You
> DS> need non-blocking sockets because you don't want to block. You
> DS> can't rely upon 'select's indication that an operation wouldn't
> DS> have blocked at some time in the past to ensure that it won't
> DS> block at some time in the future.
> Why I can't rely operation wouldn't blocked, if socket is marked
> non-blocking? Please describe exact wording from standard or show a
> widespread implementation.
Actually the standard says that it won't block.
"A descriptor shall be considered ready for reading when a call to
an input function with O_NONBLOCK clear would not block, whether or
not the function would transfer data successfully. (The function
might return data, an end-of-file indication, or an error other
than one indicating that it is blocked, and in each of these cases
the descriptor shall be considered ready for reading.)
A descriptor shall be considered ready for writing when a call to
an output function with O_NONBLOCK clear would not block, whether
or not the function would transfer data successfully."
"If a descriptor refers to a socket, the implied input function is
the recvmsg() function with parameters requesting normal and
ancillary data, such that the presence of either type shall cause
the socket to be marked as readable. The presence of out-of-band
data shall be checked if the socket option SO_OOBINLINE has been
enabled, as out-of-band data is enqueued with normal data. If the
socket is currently listening, then it shall be marked as readable
if an incoming connection request has been received, and a call to
the accept() function shall complete without blocking."
David has a different idea about what "block" means that I do. He has
a valid point though, because you have to know what an implementation
actually does. The presence of the standard doesn't guarantee
I'm staying out of it this time though :-)