On Wednesday 2008-05-28 23:22, Fausto Richetti Blanco wrote:
You could have a look at the tee(2) system call and see whether it helps
you a bit. Something along the lines of:
int pfd[2];
pipe(pfd); /* tee() wants an fd... */
tee(STDIN_FILENO, pfd[1], len, SPLICE_F_NONBLOCK);
read(pfd[0], ..., also in nonblock-mode)
Of course this also has a certain drawback, namely that the pipe will
only give you as much bytes as it carries, and no more than that,
because the write side of the pipe at STDIN_FILENO is currently
blocking exactly because the pipe is full.
In other words, at most "4K" to be read with tee().
Alternatively, if you need to consume an unspecified amount, it is
probably best to go the thread way.
--