Thanks for the reply ahmad! I was looking at alarm() and it appear to be a solution to my problem, however it breaks my code. I used like that...
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required
alarm 5;
my $sock = new Net::SOCKS(socks_addr => $socksserver, socks_port => $s
+ocksport, protocol_version => 5);
alarm 0;
};
die if $@ && $@ ne "alarm\n"; # propagate errors
if ($@) {
print("\nTIME-OUT\n");
}
else {
my $con = $sock->connect(peer_addr => '10.1.1.3', peer_port => 23);
#other parts of my code.
}
Without this alarm() the application runs without errors, but with this new alarm() code I'm getting errors:
Global symbol "$sock" requires explicit package name at ./test.pl line 48.
Execution of ./test.pl aborted due to compilation errors.
I have the main code, inside this main code I call 3 threads and inside this threads I call a function to test the connectivity, this function is where this example of code is located. I don't want to die(), well, I can call die(), but I can't exit the application, in the case of a timeout I just want to call "return" or something like that to return from this function to the previous function (the one used when I called the tread).
Can you please give a help how to fix this example of code with alarm()?
Thank you | [reply] [d/l] |
{### A NEW SCOPE
my $sock;
}### END OF SCOPE, $scope DOES NOT EXIST HERE
Tutorials: Coping with Scoping, perlintro | [reply] [d/l] |
| [reply] [d/l] [select] |
very strange, the code always die and with the unwanted message "Alarm clock", even if I replace in the code things like $SIG{ALRM} = sub { die "Timeout\n" }; or $SIG{ALRM} = sub { return; }; - There is a way to solve it? Thank you
| [reply] |
Thanks guys, it solved the problem. I'm shamed, very idiot problem. The only problem now is that when the code timeout it print a crazy error "Alarm clock" that I never asked to print. I mean, I have a own message like print ("Timeout\n"); but when the timeout happens it's never called and instead it prints this "Alarm clock" that is not in my code. There is a way to replace it with my own print timeout error? Thank you
| [reply] |
The problem continue to die even with this change. Very strange. There is no way to completely ignore the die() and just return or do nothing? I mean, just return from the function? Well, the function that has this code is called simultaneously by different threads. May it be a problem? Maybe this alarm() is no thread safe? Any other solution? Also, why I can't change this message of "Alarm clock"? Thank you.
| [reply] |
I also noticed that when this unwanted "Alarm clock" appear it kill my code, what is not what I want. I just want to return from the function, not kill/exit the whole code. How to fix it? thank you
| [reply] |