How to detect dead peer quickly in AnyEvent::Handle?

Michael Fung mike at 3open.org
Thu Feb 28 14:49:46 CET 2013


Hi Marc,

I fiddled with this new socket option for some time and could not find a 
way to set it in a perl script.

So for the time being I settled for application layer keep alive like these:

[code]
# subclass AnyEvent::Handle to add ack_pending property, then:

on_wtimeout => sub{
     my $hdl = shift;

     if ($hdl->ack_pending) {
     	# ack timeout , close	
     	do_close_handle($hdl);
     } else {
     	# send keepalive
     	$hdl->push_write ("KEEPALIVE" . $CRLF);
     	$hdl->ack_pending(1);
     };
},

on_read => sub {
     ...
     # if keepalive ack received
     $hdl->ack_pending(0);
     ...
};
[/code]


Rgds,
Michael

On 2/28/2013 7:31 PM, Marc Lehmann wrote:
> On Tue, Feb 26, 2013 at 07:48:23AM +0800, Michael Fung <mike at 3open.org> wrote:
>> Many thanks. Indeed it is a tcp related issue. I will try the
>> TCP_USER_TIMEOUT socket option if it is available on my system. For
>
> Sounds cool, and no, I haven't heard about this one before :)
>



More information about the anyevent mailing list