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:
Win32 and alarm()

 



alager
Novice

Sep 3, 2009, 3:57 PM

Post #1 of 2 (605 views)
Win32 and alarm() Can't Post

I'm making a UDP test script and the receive portion uses alarm() to test for timeouts. The problem is that calling the recv() method of IO::Socket seems to cause the alarm feature to either be reset, or just not able to create the signal.

alarm() by itself works:

Code
$SIG{ALRM} = sub { die "alarm time out" }; 
alarm(1);
sleep 4;
alarm(0);

This gives the message "alarm time out"

However, if I try this instead, the code hangs forever if there is nothing to receive, the alarm never activates

Code
$SIG{ALRM} = sub { die "alarm time out" }; 
alarm($TIMEOUT);
$sock->recv($msgRX, $MAXLEN) or die "recv: $!";
alarm(0);


I've tried this with and without an eval around it, it doesn't seem to make a difference.

Any help on this would be appreciated.

Thanks,
Aaron


(This post was edited by alager on Sep 4, 2009, 9:06 AM)


1arryb
User

Sep 8, 2009, 8:09 AM

Post #2 of 2 (578 views)
Re: [alager] Win32 and alarm() [In reply to] Can't Post

Hi alager,

The fact that your alarm is being reset inside the socket call should have twigged you to the need to deal with the timeout in your socket setup, not the surrounding Perl code. Looking at the UDP example code in the perlipc perldoc, it looks like you should set the socket timeout in your select before attempting the recv call.

Good Luck,

Larry

 
 


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

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