i want to handling blocking network reads "nicely" without using select() (because i'm already using a Perl module which hides the network I/O from me). my extremely ugly code is below. basically, put the blocking read inside an eval{} block, and use alarm() to interrupt it.
this SEEMS to work, but i'm not too confident about it because i don't know how alarm() and signal() interact with each other. certainly sleep() interferes with signal() and select() which is used for network I/O.
of course i've already thought of using Time::HiRes::ualarm() instead of plain alarm() since, on Linux at least, Time::HiRes uses setitimer() which is a totally different system call... and i'm gambling it won't affect select() --- bad gamble?
# 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 $@;
}
if (!$pdu) { return(undef); }
_________________________________________________ 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

