Multiple Reads/Writes to Socket Handles
: Good Morning,
:
: I am attempting to take STDIN from a server, and selectively read by sockets
: contained within forked clients. (Incomming messages from clients would be
: put into the STDIN stream. Is this a 'bad' thing to do?)
: Could anyone help out with this?
:
: I have been attempting to simply have the children grab STDIN and do
: what it has to, but the first child to do the read flushes the buffer.
: Is there any way around this?
: The same problem would occur when trying to use pipes. I have not tried
: this yet , but isn't STDIN just another pipe?
:
: I could try to use an array of sockets, but then not all of the children
: would know about each other.
:
: If there is a workaround, or if you have servers doing what I am looking
: for, please let me know about them.
You need to avoid using stdio in such cases. You don't say whether
you're playing with streams or datagrams. If datagrams, be sure to use
recv() instead of <> or read(). If you're working with a stream, you
should use sysread(), and never read more than you know you want,
because once you've read it, there's no way (in general) to put it back
such that it's available to a different process. In the limit, this
means nibbling STDIN one byte at a time with sysread(STDIN,$char,1).
Larry