CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Problem with Perl timeout and module DHCP WATCh

 



hemmerp
New User

Jan 15, 2013, 7:05 AM

Post #1 of 1 (1069 views)
Problem with Perl timeout and module DHCP WATCh Can't Post

Hello eveybody,

I am currently writing a script to check if a DHCP server is working. If it's working, i have to give the duration of the request. If not, an error's message.

To do this test, i am using the module NET: DHCP::WATCH (http://search.cpan.org/~ejdrs/Net-DHCP-Watch-2.03/Watch.pm ) et le module Object: Destroyer.

I have first created this small script to test my alarm/timeout.


Code
use Object::Destroyer; 

eval {

local $SIG{ALRM} = sub { die("alarm\n") };

alarm(4);
my $sentry = Object::Destroyer->new( sub {alarm(0)} );

#Get Status
sleep (2)

};
if ($@) {print "Alarm";}
else {
print "OK";}


I have played with the value of the sleep and The script is working, then the alarm/timeout is working.

I have then writen the script for the DHCP :


Code
use Time::HiRes; 
use Object::Destroyer;
use Net::DHCP::Watch;


# server name
my $Server = '192.168.1.1';
# this machine ip and ethernet address
my $IP = '192.168.1.2';
my $Ether = '00:23:CD:CE:43:DC';
my $timeout = 5;

my $stat ='';

# Net::DHCP::Watch object
my $dhcpw = new Net::DHCP::Watch({
server => $Server,
client => $IP,
ether => $Ether,
timeout => $timeout
});

# Open network
$dhcpw->watch();

my $start = [ Time::HiRes::gettimeofday( ) ];

eval {

local $SIG{ALRM} = sub { die("alarm\n") };

alarm(6);
my $sentry = Object::Destroyer->new( sub {alarm(0)} );

#Get Status
$stat = $dhcpw ->status;

};
if ($@) {

print "Error";
}
else {

$elapsed = Time::HiRes::tv_interval( $start );
$elapsed = $elapsed * 1000;

# print results

if ( $stat->{Ok} )
{
print "Remote DHCP $Server online.\n";
print "Dhcptime;$elapsed;ms";
}
else
{ print "Error";
}
}


When i put a correct and working DHCP server, the script is working fast and rapidly.

However, when i put a bad DHCP server, the script is blocking at the command "$stat = $dhcpw ->status;". The script won't stop itself even with my timeout.

I don't understand why it's not working, i suppose it's something related to the DHCP module. But i thought that my alarm will take the lead and stop the script after X seconds.

Thank you for your help or for any idea.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives