How set timeout to connect operate

Discussion in 'Perl Misc' started by yong, Jan 30, 2006.

  1. yong

    yong Guest

    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.
     
    yong, Jan 30, 2006
    #1
    1. Advertising

  2. 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/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Jan 30, 2006
    #2
    1. Advertising

  3. 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.
     
    Brian McCauley, Jan 30, 2006
    #3
  4. yong

    Guest

    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
     
    , Jan 30, 2006
    #4
  5. yong

    yong Guest

    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.
     
    yong, Jan 31, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. benn
    Replies:
    2
    Views:
    617
  2. Maya Young

    Use C# to operate a mobile device

    Maya Young, Apr 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    635
    Maya Young
    Apr 17, 2004
  3. Dux
    Replies:
    1
    Views:
    294
    Mike Wahler
    Oct 5, 2003
  4. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,334
    Brian Candler
    Oct 6, 2004
  5. Richard Maher

    How to set HTTP connect timeout

    Richard Maher, Jun 21, 2009, in forum: Javascript
    Replies:
    2
    Views:
    126
    Richard Maher
    Jun 22, 2009
Loading...

Share This Page