I'm using select(4 arg) and sysread() to read a socket. I've noticed some strange behavior that I didn't expect, and I'm looking for some insight.

First of all, I've noticed that when a signal comes in (e.g. HUP) during select(), the function returns -1. I haven't seen this documented anywhere. Is this new to perl5.8? I know signal handling has been improved in 5.8, is there any detailed doc on this?

Also, I always thought that sysread() was non-blocking, but when there is no data to read, sysread() blocks. Is there any way to grab whatever data is on the socket (if any), without blocking? I know it sounds funny, but I don't completely trust select() to tell me that there's something to read. I want to double check when select() times out that there really is nothing on the socket. Should I just use an alarm to time out sysread()?

Finally, I was told a few days ago that sysread() should be given a value to read equivalent to my system's buffer size. Is this information correct? I don't see this documented anywhere? Can it hurt to tell sysread() to read in a much larger value? What if I tell it to read in 100K? Will chaos ensue? Is my system's buffer size the maximum size that sysread() will read?


In reply to select() and sysread() by althepal

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.