<?xml version="1.0" encoding="windows-1252"?>
<node id="371745" title="Re: Using select and IO::Select" created="2004-07-04 16:15:37" updated="2005-06-03 00:44:00">
<type id="11">
note</type>
<author id="82147">
Zaxo</author>
<data>
<field name="doctext">
&lt;p&gt;[duff]++, good job and much needed.&lt;/p&gt;
&lt;p&gt;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 &lt;em&gt;not&lt;/em&gt; 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.&lt;/p&gt;
&lt;p&gt;There are some more questions I think could be covered. I don't necessarily know the answers.
&lt;ul&gt;
  &lt;li&gt;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?&lt;/li&gt;
  &lt;li&gt;Signal handling: Do signals awake a sleeping select? Does a [select] timeout affect a pending [alarm]?
&lt;p&gt;(Added) This it readily checked with a few one-liners.
&lt;code&gt;$ perl -e'alarm 1;printf "Num: %d\tTime left: %f\n", select undef, undef, undef, 3.0'
Alarm clock
$ &lt;/code&gt;
shows that setting timeout in select does not interfere with SIGALRM and that signals will awake pending select.
&lt;code&gt;$ time perl -e'alarm 5;printf "Num: %d\tTime left: %f\n", select undef, undef, undef, 3.0'
Num: 0	Time left: 0.000000
$ &lt;/code&gt;
shows that having an alarm set does not interfere with [select] timing.
&lt;code&gt;$ 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
$ &lt;/code&gt;
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.&lt;/p&gt;&lt;/li&gt;
  &lt;li&gt;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?
&lt;p&gt;(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.
&lt;code&gt;$ perl -e'printf "OS: %s\tNum: %d\tTime left: %f\n", $^O, select undef, undef, undef, 1.5'
&lt;/code&gt;
gives for several systems,&lt;br /&gt;
&lt;tt&gt;OS: linux	Num: 0	Time left: 0.000000 (Zaxo)&lt;br /&gt;
OS: freebsd Num: 0 Time left: 1.500000 (sporty)&lt;br /&gt;
OS: solaris Num: 0 Time left: 1.500000 (sporty)&lt;/tt&gt;&lt;br /&gt;
Thanks to [sporty] for his assistance with that.&lt;/p&gt;
&lt;/li&gt;
  &lt;li&gt;IO::Select:: Does the very welcome sugar coating relax the restrictions on I/O methods?&lt;/li&gt;
  &lt;li&gt;IO::Select: Does IO::Select return IO::* objects or just whatever globlike things you add?&lt;/li&gt;
  &lt;li&gt;IO::Select: A more complicated example would be welcome. Something with error handling would be good.&lt;/li&gt;
  &lt;li&gt;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.&lt;/li&gt;
  &lt;li&gt;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.&lt;/li&gt;
&lt;/ul&gt;&lt;/p&gt;
&lt;p&gt;Again, this is a very good job, and welcome information. You can run your pod through &lt;tt&gt;pod2html&lt;/tt&gt; to get a good format for posting here.&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-82147"&gt;
&lt;p&gt;After Compline,&lt;br/&gt;Zaxo&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
371720</field>
<field name="parent_node">
371720</field>
</data>
</node>
