You can either ignore SIGPIPE signals and wait for syswrite to return 0, or you can listen for SIGPIPE signals

I think you meant "return undef" here...

Call me a Un*x biggot but I have been thinking about this some more. I just could not quite remember something about SIGPIPE and sockets in the context of a select loop.

First let us look at the easy case i.e pipes or fifos. By default they are "blocking".

  • A SIGPIPE is an exceptional condition (like the receiving of any other signal except SIGCHILD maybe as it is a system "rule"): a write to a pipe or fifo without reader will generate a SIGPIPE for that writer.
  • EOF on a fifo or pipe is a normal condition, generated when the last writer on a FIFO closes it (in the case of a pipe when the writer closes it) and the reader tries to read.
  • In the context of a select loop EOF at the read end of a connection is also a normal condition. Two system calls actually cooperate: select indicates a desc.(fh) is ready for reading if the next read gives EOF; in that case Perl's sysread will return num. 0.

    Select will indicate that a desc.(fh) is ready for writing when the other end has closed its side of the connection. The next call to syswrite will return undef (and sets $! to EPIPE) and in complete analogy with the pipe/fifo case a SIGPIPE will be generated.

    Still there is an important difference, in a select loop you usually manage quite a few "write" desc. and an isolated signal does not really pinpoint the "guilty" desc.; so usually you would mostly ignore SIGPIPE in the context of a select loop (not so for a "pipeline"). This is what I could not remember at first.

    hth --stephan

    In reply to Re^4: Pipes and IO::Select's method can_write() by sgt
    in thread Pipes and IO::Select's method can_write() by almut

    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.