Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Answer: What is the easy way to check if the socket has data to read, before do a read()

( #184851=categorized answer: print w/ replies, xml ) Need Help??

Q&A > network programming > What is the easy way to check if the socket has data to read, before do a read() contributed by perlknight

Use IO::Select, pass the socket handle to it and use can_read method to detemine if the handle is ready, here's snippet from perldoc:
use IO::Socket; use IO::Select; $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080); $sel = new IO::Select( $lsn ); while(@ready = $sel->can_read) { ... }

Comment on Answer: What is the easy way to check if the socket has data to read, before do a read()
Download Code
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2015-07-31 05:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls