How are you determining that your program is losing data?

You are never going to lose any data when reading from a pipe, even if the system call is restarted. However, perhaps what could be happening is that your syswrite is getting interrupted and not writing all of $buffer. You really need to check what syswrite returns and re-buffer what didn't get written for a future write. Note that $wbytes != $rbytes doesn't necessarily mean that an error has occurred, especially when writing to a pipe. The write can be short if the pipe doesn't have enough space for the entire write buffer. The only return values from syswrite that signal an error are 0 and undef.

Update 1: I'll have to double check if a return value of 0 from syswrite signals an error. It does with the system call write but it might not be the case with perl.

Update 2: A common technique for handling an I/O buffer is as follows:

my $buf; while (1) { my $nr = sysread(IN, $buf, 1024, length($buf)); unless ($nr) { ...handle EOF or error... }; ... if (length($buf)) { my $nw = syswrite(OUT, $buf, length($buf)); unless (defined($nw)) { ...handle error... } substr($buf, 0, $nw, ''); } ... }

In reply to Re: EINTR and sysread() by pc88mxer
in thread EINTR and sysread() by bot403

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.