... in the meantime, I discovered a solution, so let me answer
my own question in case somebody else stumbles on this.

Peter Daum wrote:
> I am trying to figure out a way to write data to a fifo without
> knowing whether there is a reader available and without ever blocking.
> What I'd like is somthing like this:
> 
> sysopen(FIFO, $fifo, O_NONBLOCK|O_WRONLY)
>             or die "Can't open fifo $fifo: $!\n";
> ...;
> 
> while (my $bytes=sysread(IN,$buf,$block_size)) {
>           if ($fifo) {
>              # do other stuff:
>              ...;              
>              # write in case somebody cares to read:
>               syswrite(FIFO, $buf);
>             }
> }
> 
> Unfortunately, the open fails unless there is somebody reading from
> the fifo- It is possible to open a fifo for read without blocking, but
> I couldn't find any way to do this for writing. ...

I don't know whether this is linux-specific (the fifo man page doesn't
mention it) but with a tiny change the code above does what I want:
If you use "O_RDWR" instead of "O_WRONLY" the "open" call succeeds even
without anybody reading from the fifo. When the buffer is full it is
obviously overwritten again, so a client reads only the data that is
written after it has opened the fifo for reading, but for my porposes,
this is just what I need ...

Regards,
                            Peter Daum




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to