How set timeout to connect operate

Y

yong

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

A. Sinan Unur

yong said:
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
 
B

Brian McCauley

yong said:
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.
 
C

ced

yong said:
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...?
 
Y

yong

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top