perlmonks12 has asked for the wisdom of the Perl Monks concerning the following question:
If you try you will get ./test.pl www.google.com 1080 Test 01 Timeout www.google.com:1080 Timeout www.google.com:3128 Alarm clock It proves that the code works fine out of the thread, but on the threads it get completely crazy. I saw this possible suggestion to fix the problem: http://www.mail-archive.com/perl5-porters@perl.org/msg89360.html However, now the code gives this error and back to be very slow again, probable when the first alarm() happen it get unhanded and never more work. SIGALRM handler "a" not defined. I can't believe there is no way to fix it in perl, can someone please help me in fix this code (examples are very welcome) to work with the threads and with the alarm()? Or any other approach that make the code fast and not waiting 5 minutes per connection that is not SOCKS... Thank you#!/usr/bin/perl use Socket; use IO::Socket; use Net::SOCKS; use threads; use threads::shared; my ($host, $port) = @ARGV; mfunc(); $port = 1080; mfunc(); $port = 80; mfunc(); for my $lthrd (1..7){ my $nthrd = threads->new(\&mfunc); foreach (threads->list){ $_->join; } } $port = 22; mfunc(); sub mfunc{ eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required alarm 7; my $sock = new Net::SOCKS(socks_addr => $host, socks_port => $port, pr +otocol_version => 4); my $rsocks = $sock->connect(peer_addr => 'www.google.com', peer_port = +> 80); my $status = $sock->param('status_num'); if ($status == SOCKS_OKAY){ print "\nWorked $host:$port\n"; $sock->close(); } alarm 0; }; die if $@ && $@ ne "alarm\n"; # propagate errors if ($@) { print("\nTimeout $host:$port\n"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Threads and ALARM() - There is a solution or workaround?
by ikegami (Patriarch) on May 10, 2010 at 17:02 UTC | |
by perlmonks12 (Novice) on May 10, 2010 at 17:11 UTC | |
by ikegami (Patriarch) on May 10, 2010 at 17:20 UTC |