How to do a non-blocking write of more than one char?

Guy Harris guy at auspex.auspex.com
Fri Jan 12 11:11:15 AEST 1990


>Can you show me a program that blocks on a write() after select() has
>indicated that the descriptor is writable?

Sure - a program that writes 50,000 characters on a "write", if the
"select()" returns true because there are 2 bytes of buffer space
available in the socket.  (Or, more generally, a program that writes N
characters on a "write", when the "select()" returns true because there
are M < N bytes of buffer space left in the socket.)  Whether this will
actually occur in the real world depends on the value of "N" for any
particular write, and the value of "M" for any particular select wakeup;
the latter would depend on all sorts of things, like the type of socket,
whether you've set SO_SNDBUF, etc..

>Okay, Guy, tell me how I accomplish this: Process A writes data to a
>pipe connected to Process B. Process A must not block on its writes,
>because it has to handle other descriptors as well. Process B is an
>already-written program that assumes that its reads are non-blocking;
>it'll take EWOULDBLOCK as a read error and die horribly.

I have no idea how you'd accomplish that and, since it's not a problem
I've personally run into, it's not exactly high on my list of problems
to solve.  You have my sympathy, but that's about it....

>C'mon, guys, this is a simple question!

And it may have a simple answer like "sorry, you can't do it".



More information about the Comp.unix.questions mailing list