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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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


New User

Jan 15, 2013, 7:05 AM

Post #1 of 1 (2434 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 ( ) et le module Object: Destroyer.

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

use Object::Destroyer; 

eval {

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

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 :

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

# server name
my $Server = '';
# this machine ip and ethernet address
my $IP = '';
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

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

eval {

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

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";
{ 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