Anno Siegel wrote:
> Sébastien Cottalorda <> wrote in
> comp.lang.perl.misc:
>> Hi all,
>>
>> Several programs need to write in a pipe (created with "mknod
>> /tmp/pipe.tub p").
>> My problem is the following :
>> If no program read the other side of the pipe, all writing operations are
>> blocked.
>> I don't care if I lost information, but I'd like programs to try to write
>> to the pipe and return doing what they are programmed to.
>>
>> Here is my program:
>>
>> #================================================= ===================
>> #!/usr/bin/perl -w
>>
>> use strict;
>> use Fcntl;
>> my $named_pipe='/tmp/pipe.tub';
>> unless (-e $named_pipe){
>> die "No way" if (system("/bin/mknod $named_pipe p"));
>> }
>> unless (sysopen(PIPE, $named_pipe, O_WRONLY|O_NONBLOCK)){
>> die "Can\'t open $named_pipe : $!";
>> }
>> while(1){
>> print "Trying to write in the pipe ...";
>> print PIPE "Heelo World\n";
>> print "Done\n";
>> sleep 3;
>> }
>> close(PIPE);
>> exit;
>> #================================================= ====================
>>
>> When I run that program, I get:
>> Can`t open pipe: Device not configured at line 10
>>
>> What's wrong ????
>> My OS: Mandrake 7.1 (kernel 2.2.15-4mdk)
>> My Perl: perl 5.6.0
>
> Nothing is wrong, it's working to specification. A pipe can't be opened
> for writing when there's no reader at the other end.
>
> The solution is not to die when open() fails (why sysopen, btw?), but
> do other things an try again later. It would also be a good idea to
> install a SIGPIPE handler in case the reader disappears while you're
> writing.
>
> Anno
Hi,
Thanks Ano,
that's helps me to solve my problem:
* intercepting SIGPIPE,
* bypassing open error,
* re-try to open again the pipe,
allow me to manage correctly my pipe.
thanks again.
Sébastien
--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
|