Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: Timeout for an established connection

by 0day (Sexton)
on Jan 01, 2013 at 22:20 UTC ( [id://1011191]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Timeout for an established connection
in thread Timeout for an established connection

Thanks... but, unfortunately I did not find this flag in perl modules.
  • Comment on Re^4: Timeout for an established connection

Replies are listed 'Best First'.
Re^5: Timeout for an established connection
by BrowserUk (Patriarch) on Jan 01, 2013 at 22:27 UTC
    I did not find this flag in perl modules.

    Look up the appropriate numeric value in your C-runtime header files and use that.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Dear BrowserUk, thank you for your reply.
      Please tell me what to do if the call setsokopt
      setsockopt($sock, 6, 18, pack("QQ", 5, 0)) or die "setsockopt SOL_TCP, TCP_USER_TIMEOUT: $!\n";
      returns an error "protocol not available"?
        "protocol not available"

        Assuming you're on some form of *nix, you could investigate whether a newer version based on a later kernel has implemented this (relatively new) option in its tcpip stack.

        Barring that, you would have no option but to effectively implement it yourself within your application.

        One way to do that would be each time you successfully send a request, push the socket handle for that client into a hash of arrays keyed by the timeout elapse time. And then each time your poll returns or times out, once you have dealt with any events returned by poll, inspect the array for the curent timeslot (if any), close the handles and remove them from your poll list.

        In an attempt to clarify: After a successful send, push the socket handle to an array keyed by the current time rounded to neasest second + your desired timeout:

        if( $sock->send( <rRE> ) ) { push @{ $timeouts{ int( time() ) + 10 ) }, $sock; } else { ## handle send failures }

        The, at the bottom o fyour poll loop:

        ... for my $sock ( @{ $timeouts{ int( time() ) { shutdown $sock, 2; close $sock; $poll->remove( $sock ); ## log failure. }

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
      Some more code:
      socket (my $sock, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die +"socket: $!"; if(fcntl ($sock, F_SETFL, O_NONBLOCK)){ my $iaddr = inet_aton(${$sock}->{host}) or return; my $paddr = sockaddr_in( ${$sock}->{port}, $iaddr ) or return; setsockopt($sock, SOL_SOCKET, SO_SNDTIMEO, pack("QQ", ${$sock}->{t +imeout}, 0)) or die "setsockopt SOL_SOCKET, SO_SNDTIMEO: $!\n"; setsockopt($sock, SOL_SOCKET, SO_RCVTIMEO, pack("QQ", ${$sock}->{t +imeout}, 0)) or die "setsockopt SOL_SOCKET, SO_RCVTIMEO: $!\n"; setsockopt($sock, 6, 18, pack("QQ", 5, 0)) or die "setsockopt SOL_ +TCP, TCP USER TIMEOUT: $!\n";
Re^5: Timeout for an established connection
by zentara (Archbishop) on Jan 02, 2013 at 10:53 UTC
      To zentara. I want to give you some advice.
      1. read carefully the question.
      2. dump from this topic.
      Thank you.
        0day, may I ask you what is wrong in suggesting you use Fcntl to get the Perl.h header files so you can use the setsockoptions by name instead of hex numbers? Also, what is wrong with the link I gave you on how to solve the problem at connection timeouts?


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1011191]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found