Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: blocking socket and alarm

by ozone (Friar)
on Sep 05, 2006 at 16:59 UTC ( #571284=note: print w/replies, xml ) Need Help??


in reply to blocking socket and alarm

A more robust (and portable) approach is to perform a 'select' call on the socket handle with a 60 second timeout. That way you don't have to worry about any signal nastiness.

Either use IO::Select or the second form from perldoc -f select

Replies are listed 'Best First'.
Re^2: blocking socket and alarm
by ikegami (Patriarch) on Sep 05, 2006 at 17:07 UTC

    It's also much simpler. Why didn't I think of that?

    use IO::Select (); sub socket_read { my $sel = IO::Select->new($socket); while (!$sel->can_read(60)) { print STDERR "Received alarm\n"; } my $len = $socket->sysread($line, 1024); ... }

    Reference: IO::Select

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-05-28 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?