Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Perl select function mystery

by rodion (Chaplain)
on Mar 28, 2007 at 01:09 UTC ( #606894=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://606894]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2021-09-18 22:36 GMT
Find Nodes?
    Voting Booth?

    No recent polls found