Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Pipes and non blocking writing

Reply
Thread Tools

Pipes and non blocking writing

 
 
Sébastien Cottalorda
Guest
Posts: n/a
 
      04-20-2004
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

Thanks in advance for any kind of help.

Sébastien
--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      04-20-2004
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
 
Reply With Quote
 
 
 
 
Sébastien Cottalorda
Guest
Posts: n/a
 
      04-20-2004
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 ]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Non-blocking and semi-blocking Sockets class. nukleus Java 14 01-22-2007 08:22 PM
Non-blocking pipes during subprocess handling Tom Plunket Python 3 01-09-2007 10:53 PM
perl problem with select and non-blocking sysread from multiple pipes john Perl Misc 7 03-04-2005 02:34 PM
Blocking and non blocking assignment in VHDL Hendra Gunawan VHDL 1 04-08-2004 06:03 AM
blocking i/o vs. non blocking i/o (performance) Andre Kelmanson C Programming 3 10-12-2003 02:09 PM



Advertisments