Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

duff++, good job and much needed.

One of the great things about select is its efficiency. Instead of busying around a polling loop, select lets your process go to sleep until there is something to do. That does not speed up the process where select is, but rather frees its time slice for all the other processes you and other users may run. It's the neighborly thing to do, and good for throughput.

There are some more questions I think could be covered. I don't necessarily know the answers.

  • I/O methods: When can Perl's buffered I/O methods be used with select? The perldoc warns that sysread (and by extension, syswrite) is necessary, except as provided by POSIX. What does POSIX permit?
  • Signal handling: Do signals awake a sleeping select? Does a select timeout affect a pending alarm?

    (Added) This it readily checked with a few one-liners.

    $ perl -e'alarm 1;printf "Num: %d\tTime left: %f\n", select undef, und +ef, undef, 3.0' Alarm clock $
    shows that setting timeout in select does not interfere with SIGALRM and that signals will awake pending select.
    $ time perl -e'alarm 5;printf "Num: %d\tTime left: %f\n", select undef +, undef, undef, 3.0' Num: 0 Time left: 0.000000 $
    shows that having an alarm set does not interfere with select timing.
    $ perl -e'$SIG{ALRM}=sub {};alarm 1;printf "Num: %d\tTime left: %f\n", + select undef, undef, undef, 3.0' Num: -1 Time left: 2.000000 $
    shows that catching a signal will jolt select into returning with -1 in the number slot. On Linux the time left value would be useful in graceful recovery from such interruptions.

  • Return values: What's a good use for the number of ready channels? What systems return something useful for the time remaining? Linux does, are there others?

    (Added) Truth or not of the number tells whether the return from select was due to a timeout. As we saw, -1 means return due to interruption by catching signal. The number can be decremented with each channel handled to enable a quick test for completion. The timeleft value appears to be useful only on Linux. $ perl -e'printf "OS: %s\tNum: %d\tTime left: %f\n", $^O, select undef, undef, undef, 1.5' gives for several systems,
    OS: linux Num: 0 Time left: 0.000000 (Zaxo)
    OS: freebsd Num: 0 Time left: 1.500000 (sporty)
    OS: solaris Num: 0 Time left: 1.500000 (sporty)

    Thanks to sporty for his assistance with that.

  • IO::Select:: Does the very welcome sugar coating relax the restrictions on I/O methods?
  • IO::Select: Does IO::Select return IO::* objects or just whatever globlike things you add?
  • IO::Select: A more complicated example would be welcome. Something with error handling would be good.
  • Applications: What is a good way to get per-handle switching of I/O? That is needed for many sorts of servers, where responses to requests need to be directed to a particular channel.
  • Applications: Adding and removing handles on the fly. This is needed for servers which open new sockets in response to requests to a well-known port.

Again, this is a very good job, and welcome information. You can run your pod through pod2html to get a good format for posting here.

After Compline,

In reply to Re: Using select and IO::Select by Zaxo
in thread Using select and IO::Select by duff

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (4)
    As of 2021-04-18 18:21 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found