in reply to Using select and IO::Select
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.
shows that setting timeout in select does not interfere with SIGALRM and that signals will awake pending select.$ perl -e'alarm 1;printf "Num: %d\tTime left: %f\n", select undef, und +ef, undef, 3.0' Alarm clock $
shows that having an alarm set does not interfere with select timing.$ 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 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.$ 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 $ - 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,
Zaxo