in reply to Perl select function mystery
How select are used to manage multiple listening sockets?When you need to wait for data coming in on either of two sockets, with file numbers 5 and 8, for example, you set bits 5 and 8 in $rin, and call select($rout=$rin,undef,undef). The select() will wait for data and return when either file number 5 or file number 8 has data to read. You will then need to know which one, and this is why you need $rout which select() will set for you. If bit 5 in $rout is set, then the socket with file number 5 has something to read. If bit 8 is set, then socket number 8. If both are set, then both sockets have something to read.
This allows you to only check a socket when you know it's got something you want, and select will wait without chewing up a lot of CPU cycles.
If you are writing code instead of reading it, I also second Joost's suggestion of IO::Select.
|
|---|