Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^7: Timeout for an established connection

by BrowserUk (Patriarch)
on Jan 02, 2013 at 21:05 UTC ( [id://1011345]=note: print w/replies, xml ) Need Help??


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

"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.

Replies are listed 'Best First'.
Re^8: Timeout for an established connection
by 0day (Sexton) on Jan 02, 2013 at 21:43 UTC
    Thank you. This is something I have long done.

      What OS are you using?

      It looks like all linux kernels since 2.6.32 has implemented TCP_USER_TIMEOUT; which would definitely be the better option if it is available to you.

      This is something I have long done.

      Hm. Makes me wonder why you are asking here, if you already have a solution?


      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.
        >What OS are you using?
        Debian 2.6.32-5-amd64 #1 SMP Sun Sep 23 10:07:46 UTC 2012 x86_64 GNU/Linux
        Maybe this is an error in the syntax? "setsockopt($sock, 6, 18, pack("QQ", 5, 0))"

        >Hm. Makes me wonder why you are asking here, if you already have a solution?
        Because this solution does not seem to me the best.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-20 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found