[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: The select() API
On Thu, 24 Feb 2000, Daniel Feiglin wrote:
> I'm still rather mysified by it ....
i'd say - just write the code as you understand it, and play with it a
little.
the major difference with selecting for read() and selecting for write()
is - when to do this.
when you select for read(), you place the file descriptor inside the
select loop all the time, because you want to be notified as soon as
there's input waiting to be read. when you select for write - you place
the file descriptor in the select loop only when you've got something to
write to that specific socket. select will tell you that this file
descriptor is active for writing, whenever there is space (in your LOCAL
system's socket buffer) to write data.
a "real" server whose main loop is based on select() (or poll()) would use
this feature in one of two methods:
1. use a select() call with a '0' timeout before trying to write to a
socket. if the select call does not indicate that this file descriptor
is active, the file descriptor is added to the server's main select set
of write FDs. after empting that socket's write queue, it's removed
from the write set.
2. similar to the above, but including setting the socket to work in
non-blocking mode. this is done because even if select() shows that a
file descriptor's buffer has free space - there is no indication as to
how much free space there is, and thus, a write() onto that file
descriptor may still get blocked.
now, i'd say - go and play with this for a bit, and keep your eyes on
steven's book while doing that, to check how to deal with the various
kinds of error conditions that might arise here.
guy
"For world domination - press 1,
or dial 0, and please hold, for the creator." -- nob o. dy
=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il