Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: SIGALRM and gethostbyaddr

by chip (Curate)
on Mar 18, 2004 at 01:40 UTC ( [id://337578]=note: print w/replies, xml ) Need Help??


in reply to Re: SIGALRM and gethostbyaddr
in thread SIGALRM and gethostbyaddr

it's also possible to set an unsafe signal with POSIX::sigaction, without switching the entire Perl program to unsafe signals. (Recent sigactions will actually let you set a signal safe or unsafe.)

It's worth noting, BTW, that unsafe signals are called "unsafe" for a reason. What you really need is a C signal handler in an XS or with Inline::C that can just return without causing even the slightest disturbance to Perl's interpreter state.

    -- Chip Salzenberg, Free-Floating Agent of Chaos

Replies are listed 'Best First'.
Re: Re: Re: SIGALRM and gethostbyaddr
by jfroebe (Parson) on Mar 18, 2004 at 16:15 UTC
    Here is the new code using use Sys::SigAction. Thanks!!!
    use Sys::SigAction qw( set_sig_handler ); .... eval { my $code = sub { die "alarm clock restart"; }; my $h = Sys::SigAction::set_sig_handler( 'ALRM', $code, { +flags => 0, safe => 1 } ); alarm 10; # schedule alarm for every 10 seconds eval { ($my_name, $my_aliases, $addrtype, $my_length, @my_add +r) = gethostbyname($my_hostname); }; alarm 0; }; alarm 0; die if $@ && $@ !~ /alarm clock restart/; #reraise
Re: Re: Re: SIGALRM and gethostbyaddr
by jfroebe (Parson) on Mar 18, 2004 at 15:33 UTC
    thanks to both of you... I'm doing mass lookups of about 4,000 ip addresses and a tiny amount don't resolve within a reasonable amount of time.. there are a tiny number that need to be looked up on other nameservers...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-19 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found