TCP keepalive?

2009-10-19 Thread Adams Sean



What is the best way to enable TCP keepalive on a  
POE::Component::Client::TCP session?



I am using POE for home automation and I have connections which are  
often idle for hours, or only get traffic in the receive direction. In  
these cases there is no indication that the connection has failed if,  
for example, the endpoint resets due to power outage.





Re: TCP keepalive?

2009-10-20 Thread Adams Sean


never mind, this was easy to enable globally by modifying  
SocketFactory.pm @ line 706:


  setsockopt($socket_handle, SOL_SOCKET, SO_KEEPALIVE, 1) or do {
$poe_kernel->yield(
  $event_failure,
  'setsockopt', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
  };

Although I think POE should expose the option to users of  
Client::TCP... do you want a patch for this?



On Oct 19, 2009, at 11:14 AM, Adams Sean wrote:




What is the best way to enable TCP keepalive on a  
POE::Component::Client::TCP session?



I am using POE for home automation and I have connections which are  
often idle for hours, or only get traffic in the receive direction.  
In these cases there is no indication that the connection has failed  
if, for example, the endpoint resets due to power outage.







Re: TCP keepalive?

2009-10-21 Thread flw
new POE::Component::Client::TCP(
  .
  .
  Connected => {
my ($socket, $peer_addr, $peer_port) = @_[ARG0, ARG1, ARG2];
setsockopt( $socket, SOL_SOCKET, SO_KEEPALIVE, 1 );
  }
  .
);



2009/10/21 Adams Sean 

>
> never mind, this was easy to enable globally by modifying SocketFactory.pm
> @ line 706:
>
>  setsockopt($socket_handle, SOL_SOCKET, SO_KEEPALIVE, 1) or do {
>$poe_kernel->yield(
>  $event_failure,
>  'setsockopt', $!+0, $!, $self->[MY_UNIQUE_ID]
>);
>return $self;
>  };
>
> Although I think POE should expose the option to users of Client::TCP... do
> you want a patch for this?
>
>
>
> On Oct 19, 2009, at 11:14 AM, Adams Sean wrote:
>
>
>>
>> What is the best way to enable TCP keepalive on a
>> POE::Component::Client::TCP session?
>>
>>
>> I am using POE for home automation and I have connections which are often
>> idle for hours, or only get traffic in the receive direction. In these cases
>> there is no indication that the connection has failed if, for example, the
>> endpoint resets due to power outage.
>>
>>
>>
>


Re: TCP keepalive?

2009-10-21 Thread Rocco Caputo
Can it be done in an extensible, sustainable way?  We can add a  
constructor parameter and code to handle every possible socket option,  
but I would like to see something better.


For example, would it make sense to pass socket options as an array of  
setsockopt() parameters?  They could be applied to the socket in  
sequence:


SocketOptions => [
  [ SOL_SOCKET, SO_KEEPALIVE, 1 ],
  [ another option ],
  ...,
],

Possibly not, since some setsockopt() calls may need to know the  
previous value of an option.  flw's suggestion to use a Connected  
callback makes more sense.  You should be able to do anything you need  
there, no matter what that entails.


--
Rocco Caputo - rcap...@pobox.com


On Oct 20, 2009, at 13:48, Adams Sean wrote:



never mind, this was easy to enable globally by modifying  
SocketFactory.pm @ line 706:


 setsockopt($socket_handle, SOL_SOCKET, SO_KEEPALIVE, 1) or do {
   $poe_kernel->yield(
 $event_failure,
 'setsockopt', $!+0, $!, $self->[MY_UNIQUE_ID]
   );
   return $self;
 };

Although I think POE should expose the option to users of  
Client::TCP... do you want a patch for this?



On Oct 19, 2009, at 11:14 AM, Adams Sean wrote:




What is the best way to enable TCP keepalive on a  
POE::Component::Client::TCP session?



I am using POE for home automation and I have connections which are  
often idle for hours, or only get traffic in the receive direction.  
In these cases there is no indication that the connection has  
failed if, for example, the endpoint resets due to power outage.