Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 15th, 2013, 03:37 AM
linecool linecool is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 linecool User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 47 sec
Reputation Power: 0
Help about Perl Timeout and the Module DHCP Watch

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 your idea.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Help about Perl Timeout and the Module DHCP Watch

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap