Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   How set timeout to connect operate (http://www.velocityreviews.com/forums/t896342-how-set-timeout-to-connect-operate.html)

yong 01-30-2006 04:20 AM

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.

A. Sinan Unur 01-30-2006 05:24 AM

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


Brian McCauley 01-30-2006 01:54 PM

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.


ced@carios2.ca.boeing.com 01-30-2006 08:13 PM

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


yong 01-31-2006 05:53 AM

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 05:00 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.