menth0l has asked for the wisdom of the Perl Monks concerning the following question:
Is there a way to timeout a print/read operations on tcp socket on ActiveState Perl 5.12?
1. Timeout option in socket constructor is related to connect/accept calls so it's useless for me
2. trick with eval/$SIG{ALRM}/alarm() don't work on ActiveState Perl (AFAIK ALRM signal is not supported)
Is there any other way?
This brings me to another question, threads-related. Let's assume that my thread is performing a "blocking" operation like: executing a SQL procedure, reading from socket (as in above example) or is locked at a semaphore. How can i break execution of that thread? Sending signals won't work since they are processed only after the blocking operation is completed. Is that even possible?
In above example i would like to wait max 3 seconds for a message and then close this connection. I found that these solutions don't work:my $sock = new IO::Socket::INET( LocalHost => $address, LocalPort => 0, Proto => 'tcp', Listen => 10, Reuse => 1, ); my $s = $sock->accept; # how to timeout this? my $message = <$s>;
1. Timeout option in socket constructor is related to connect/accept calls so it's useless for me
2. trick with eval/$SIG{ALRM}/alarm() don't work on ActiveState Perl (AFAIK ALRM signal is not supported)
Is there any other way?
This brings me to another question, threads-related. Let's assume that my thread is performing a "blocking" operation like: executing a SQL procedure, reading from socket (as in above example) or is locked at a semaphore. How can i break execution of that thread? Sending signals won't work since they are processed only after the blocking operation is completed. Is that even possible?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Locked threads and tcp timeouts
by BrowserUk (Patriarch) on Feb 16, 2012 at 12:57 UTC | |
by menth0l (Monk) on Feb 16, 2012 at 13:19 UTC | |
| |
Re: Locked threads and tcp timeouts
by zentara (Archbishop) on Feb 16, 2012 at 17:02 UTC | |
by BrowserUk (Patriarch) on Feb 16, 2012 at 17:05 UTC | |
by nikosv (Deacon) on Feb 19, 2012 at 15:42 UTC | |
by BrowserUk (Patriarch) on Feb 20, 2012 at 02:50 UTC | |
Re: Locked threads and tcp timeouts
by Khen1950fx (Canon) on Feb 19, 2012 at 22:18 UTC |
Back to
Seekers of Perl Wisdom