Okay, non-blocking IO gives me an error, errno == EAGAIN, when no data is available. So then I can loop and busy-wait on data becoming available? Ick! So I put in a usleep(10), and that dropped the CPU use from 100% to 0% while waiting for input, which seems like it's low enough to not bother about too much (dozens of clients, remember; if it were thousands I might have to work harder). So this works in my test code, and it seems to work in my real code as well (test cases running as I type).

The other choice is select(), but select requires sysread rather than ordinary read, meaning I'd have to do my own buffering implementation for the cases where I have to read line-oriented data. That might be the solution if I needed to support thousands of clients, though, it'd probably waste less cpu horsepower than my usleep(10) does.

This should be core perl territory, and I feel like I'm struggling quite a lot due to the environment not making it easy. Am I missing a better way? Or do I just have to do this over and over until it becomes simple and comfortable in my head?

The documentation could have saved me days of annoyance by being a bit clearer about how read() behaves.


In reply to Re: Socket descriptor passed across fork -- hanging by dd-b
in thread Socket descriptor passed across fork -- hanging by dd-b

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.