Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How set timeout to connect operate

Reply
Thread Tools

How set timeout to connect operate

 
 
yong
Guest
Posts: n/a
 
      01-30-2006
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.
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-30-2006
yong <> wrote in news:drk464$l86$:

> 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 <>
(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

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      01-30-2006
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.

 
Reply With Quote
 
ced@carios2.ca.boeing.com
Guest
Posts: n/a
 
      01-30-2006

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

 
Reply With Quote
 
yong
Guest
Posts: n/a
 
      01-31-2006
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to set HTTP connect timeout Richard Maher Javascript 2 06-21-2009 11:52 PM
maximum clock speed so that a design can safely operate benn VHDL 2 03-14-2005 06:47 AM
Timeout::timeout and Socket timeout Mark Probert Ruby 1 10-06-2004 09:30 AM
Use C# to operate a mobile device Maya Young ASP .Net 2 04-17-2004 09:07 PM



Advertisments