I'm having some problems with named pipes, and was hoping some monk could shed some light for me. The problem that I'm having is thus:

I have a program that sits waiting for some other program to open a named pipe, at which point it reads all the data from the named pipe, closes the pipe, and acts on the data (it's going to be a mail filter). It then goes back to the start, waiting for another program to open the pipe.

The problem is, if the writer opens the pipe too many times, in too short of a period, the reader ends up losing entire sessions of the opened pipe (ie, I never get partial data, just entire times that the pipe was opened by the writer are never seen by the reader).

When I try to reduce this to a simple example, however, I get a different problem. In the following simple programs, tstin.pl sometimes gets all the data from tstout.pl in a single connection, instead of one line per connection, as tstout.pl is actually sending it. So, closing the pipe in tstout.pl doesn't seem to propagate to tstin.pl for some reason.

It seems very strange to me, but perhaps I'm missing something. I look forward to any advice, or suggestions.


tstin.pl

#!/usr/bin/perl use warnings; use 5.6.0; use IO::Handle; STDOUT->autoflush(1); STDERR->autoflush(1); $SIG{PIPE} = sub { die "SIGPIPE: (@_) $!\n" }; $/ = undef; while(1) { print "Opening pipe: "; open $pipe, "< tst.fifo" or die "Can't open pipe: $!\n"; $pipe->autoflush(1); print "got pipe, reading:\n"; print map ": $_\n", split "\n", scalar <$pipe>; print "Pipe done, closing: "; close $pipe or die "Can't close pipe: $!\n"; print "done.\n"; print "Taking a long time... "; sleep 3; } exit;

tstout.pl

#!/usr/bin/perl use warnings; use 5.6.0; use IO::Handle; STDOUT->autoflush(1); STDERR->autoflush(1); $SIG{PIPE} = sub { die "SIGPIPE: (@_) $!\n" }; $delay = shift || 0; @data = map "$_\n", split "\n", <<'EOD'; This is some silly, stuff to be sent to the pipe where hopefully it will be read. EOD while(@data and $_ = shift @data) { open $pipe, "> tst.fifo" or die "Can't open pipe: $!\n"; $pipe->autoflush(1); print $pipe $_; close $pipe or die "Can't close pipe: $!\n"; sleep $delay if $delay; } exit;

(Occasional) tstin.pl Output

Opening pipe: got pipe, reading: : This is some silly, : stuff to be sent : to the pipe where hopefully : it will be read. Pipe done, closing: done. Taking a long time... done.

bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.


In reply to Named pipes missing connections by bbfu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.