On Mon, Nov 21, 2005 at 11:31:50AM +0800, Orlando Andico wrote:
> # now wait for packets.. dirty dirty code
> eval {
> print STDERR "waiting for PDU..\n" if ($SMPPDEBUG);
>
> local $SIG{ALRM} = sub { die "alarm" };
> alarm(1);
> $pdu = $SMPPCONN->read_pdu()
> or die "$$: PDU not read. Closing connection";
> alarm(0);
> };
>
> # if the cause of "death" was NOT an alarm, that means something
> # serious is going on..
> if ($@ && $@ !~ /alarm/) {
> die $@;
> }
According to this link[1], that alarm code may not work in 5.8.x because
starting from 5.8.0[2] Perl delays signal delivery, making signals
safe[3]. A better solution is to use POSIX signal handlers. There is an
example in the third link under "Interrupting IO", but a more complete
example can be found in the first link.
Here (stolen from the first link):
use POSIX qw(SIGALRM);
my $mask = POSIX::SigSet->new( SIGALRM );
my $action = POSIX::SigAction->new(sub { die "alarm" }, $mask);
my $oldaction = POSIX::SigAction->new();
POSIX::sigaction(SIGALRM, $action, $oldaction );
eval {
alarm 2;
sleep 10 # some real code should be here
alarm 0;
};
POSIX::sigaction(SIGALRM, $oldaction); # restore original
warn "got alarm" if $@ and $@ =~ /alarm/;
[1]
http://perl.apache.org/docs/2.0/user/coding/coding.html#Using_Signal_Handlers
[2] http://search.cpan.org/dist/perl/pod/perl58delta.pod#Safe_Signals
[3]
http://search.cpan.org/dist/perl/pod/perlipc.pod#Deferred_Signals_%28Safe_Signals%29
HTH
--
$_=q:; # SHERWIN #
70;72;69;6e;74;20;
27;4a;75;73;74;20;
61;6e;6f;74;68;65;
72;20;50;65;72;6c;
20;6e;6f;76;69;63;
65;27;:;;s=~?(..);
?=pack q$C$,hex$1;
;;;=egg;;;;eval;;;
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
[email protected] (#PLUG @ irc.free.net.ph)
Read the Guidelines: http://linux.org.ph/lists
Searchable Archives: http://archives.free.net.ph