I see your point now. For some reason I thought that undef value would always evalutes to false in conditional statements in perl. However, when I thought more about it and given the fact that $! is a 'synonym' for C's errno, I see no guaranty that it would be reset to some specific value if no system error occurs and may indeed contain phantom residule value that could evaluate to true. Basically, without looking through perl's code there is no way to say which statement is true.

Here is a modified version of the read_msg sub...

sub read_msg { my ($sock, $bcount, $buf, $msg) = (shift, 0, '', ''); my $bytes_read; # Use sysread for stream-oriented sockets READ_MSG: while ($bytes_read = sysread($sock, $buf, 1024)) { # Handle partial read $bcount += $bytes_read; $msg .= $buf; } # sysread returns undef on system error, check $! if (not defined $bytes_read) { # Just in case, save $! value my $error = $!; # To be safe here... redo READ_MSG if $error =~ /Resource temporarily unavailable/; # All other errors trigger unconditional return with error return ($msg, $bcount, $error); } # Return success return ($msg, $bcount, ''); }

In reply to Re^5: No data received on client socket by caelifer
in thread No data received on client socket by rbi

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.