How to change a unamed pipe and socket file descriptors readiness ?



Hi folks!

First of all, I'm using Linux Kernel 2.6.16 and GlibC 2.3.6.
I'm writing a program (say 'fwd') which reads data from a unamed pipe
(in future I gonna implement it
with socket support) and write it to another.
For now, I'm reading from STDIN_FILENO file descriptor. First I set it
to O_NONBLOCK with fcntl(),
put it in a fd_set and call select() and test it readiness when
select() returns.
So, I do at shell:

$ cat file.txt | ./fwd

Since STDIN_FILENO is non blocking, I make a loop with read() until it
returns 0, so no more data
is ready to be read.
When I call select() again, it imediately returns telling that
STDIN_FILENO 'is' ready to be read. But read()
tell me there's no more data to be read. So... How can I change (or
reset) it's readiness state?
I don't what to close() this file descriptor... because my interest is
that this 'fwd' application will be
spawned by another daemon which I will pipe(), dup2() and fork() and
execv() it and send a data from
parent to child process ('fwd') time by time... so I need this pipe
open at both ends.

Hope I was clear.

thanks a lot in advance, regards
Lucas Brasilino

.



Relevant Pages

  • Re: Pthread fd and memory leak
    ... and closes the socket file descriptor. ... When you send an fd over a pipe, the fd is still open in the sending ... memory at the pointer value and free it without errors, ...
    (comp.programming.threads)
  • Re: what happens to Popen()s parent-side file descriptors?
    ... This means that somewhere a pipe file descriptor is opened on the ... parent side to read from the child's stdout. ... to the child process, until *all* data are sent and received. ...
    (comp.lang.python)
  • Re: Question about pipes
    ... >> (or even pseudo code). ... > It presupposes that on your system, file descriptor zero refers ... > is attached to the read end of the pipe. ... > the child may block if there is insufficient ...
    (comp.unix.programmer)
  • Re: fd redirection and gdb
    ... When A starts, A runs pipe(), then fork, redirects file descriptors, ... stopping there, it works; A speaks, B answers; all normal. ... except maybe as a gdb bug. ... as if I were writing on the wrong file descriptor after I grabbed the ...
    (comp.unix.programmer)
  • Re: Question about pipes
    ... >> (or even pseudo code). ... > It presupposes that on your system, file descriptor zero refers ... > is attached to the read end of the pipe. ... > the child may block if there is insufficient ...
    (comp.os.linux.misc)