:
(E-Mail Removed)
: I'm trying to write client/server networking applications and I've hit
: a bit of a snag. After establishing a connection between client and
: server, data needs to flow asynchronously; that is, I want both the
: client and server to be able to initiate data transfers to the other
: node.
:
: The select() function immediately comes to mind. If I understand this
: function correctly, it can block until there is data to read or it's
: safe to write. However, most of the time it will be safe to write and
: there will be nothing for it to do. Then I'll need to call select()
: again... and I'll have an ugly busy-waiting loop. Someone please
: tell me if I'm wrong...
Do you have anything to write? If not, why are you asking select
to wake you up when it's safe to write?
Hence: to avoid the busy loop, simply select only on the various inputs
if you have nothing to write: if you DO have something to write (and
need to ensure it's safe, ie, won't block) you could include the write
socket in the select; but then, you won't be in a busy loop, you'll
be writing something, then deciding what to wait on the next time.
Or put it this way: you select only on events for which you will have
work to do; if the only thing you would do for an event is wait some
more, you don't ask to wake up for that event, since you're already waiting.
Wayne Throop
(E-Mail Removed) http://sheol.org/throopw