
Newbie Question: select function
Quote:
> I just started working with sockets.
> I wonder if the writefds argument for the select function is for
> non-blocking write purpose because I don't really see the real use of
> this argument for blocking write. It would be only useful if in the
> select loop when an fd is ready for writing then some data can be
> write to it without "for" looping on the write.
> Am I correct ?
> Thanks,
> Ming
I think your question is off topic for this newsgroup - the people on
comp.unix.programmer are very nice and will help you out.
In my own amateur way, I could attempt to answer your question. If the
fd is non blocking, you could just have a for loop, where you keep
attempting to write. The problem with this is that going around this
for loop will use up a lot of CPU cycles. On a multiuser system like
Unix, these CPU cycles could have been used by some other process. Or
if there is no other process that needs to work, the computer could
execute a halt instruction, thus saving the CPU from heating up. But if
you wait upon a select command (even if it has a timeout), you give back
that time to the kernel, and the kernel can give that time to a process
that has real work to do.
--
Stephen Montgomery-Smith
http://www.math.missouri.edu/~stephen