![]() |
How set timeout to connect operate
I want to stop a connect operate and I don't want to use
IO::Socket::INET.So I put the connect function into a thread,but there seems no way to force a thread stop. Is there some way to stop a socket connect operate? Thanks. |
Re: How set timeout to connect operate
yong <luoyong_zh@hotmail.com> wrote in news:drk464$l86$1@news.yaako.com:
> I want to stop a connect operate and I don't want to use > IO::Socket::INET.So I put the connect function into a thread,but there > seems no way to force a thread stop. > > Is there some way to stop a socket connect operate? I am having a hard time making sense of your question. Please consult the posting guidelines for this group. Please post a short but complete script that others can run to see what you are talking about. Sinan -- A. Sinan Unur <1usa@llenroc.ude.invalid> (reverse each component and remove .invalid for email address) comp.lang.perl.misc guidelines on the WWW: http://mail.augustmail.com/~tadmc/cl...uidelines.html |
Re: How set timeout to connect operate
yong wrote:
> I want to stop a connect operate and I don't want to use > IO::Socket::INET. Am I missing something or are you asking FAQ: "How do I timeout a slow event?" > So I put the connect function into a thread,but there > seems no way to force a thread stop. I don't know. Threads are very expensive in Perl5 and should be avoided for simple tasks like this. > Is there some way to stop a socket connect operate? Well, if IO::Socket::INET does it (in pure Perl) then there must be a way, and you must be able to find out what this way is by consulting the source code of IO::Socket::INET. |
Re: How set timeout to connect operate
yong wrote: > I want to stop a connect operate and I don't want to use > IO::Socket::INET.So I put the connect function into a thread,but there > seems no way to force a thread stop. > > Is there some way to stop a socket connect operate? > IO::Socket::INET provides a timeout option: my $sock = IO::Socket::INET->new( timeout => 5, ...) You could instead wrap this in a eval, alarm block as suggested but you would be adding unnecessary complexity for no perceivable gain. eval { local $SIG{ALRM} = sub { die "timeout";} alarm(5); my $sock = IO::Socket::INET->new( timeout => 5, ...); alarm 0; }; Is there some reason you can't use IO::Socket::INET's own timeout...? -- Charles DeRykus |
Re: How set timeout to connect operate
ced@carios2.ca.boeing.com wrote:
> yong wrote: > >>I want to stop a connect operate and I don't want to use >>IO::Socket::INET.So I put the connect function into a thread,but there >>seems no way to force a thread stop. >> >>Is there some way to stop a socket connect operate? >> > > IO::Socket::INET provides a timeout option: > > my $sock = IO::Socket::INET->new( timeout => 5, ...) > > You could instead wrap this in a eval, alarm block as suggested but you > would be adding unnecessary complexity for no perceivable gain. > > eval { > local $SIG{ALRM} = sub { die "timeout";} > alarm(5); > my $sock = IO::Socket::INET->new( timeout => 5, ...); > alarm 0; > }; > > Is there some reason you can't use IO::Socket::INET's own timeout...? > I rewite my code.Using $SIG{} instead of threads to set timeout although it's platform-dependence. Thanks all. |
| All times are GMT. The time now is 09:22 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.