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.









Re: patch for PoCo::IKC::ClientLite.pm

2009-10-21 Thread flw
repost to whole mail list.

2009/10/22 flw 

> Sorry for my english. I am happy to use code instead of English to
> illustrate the problem.
>
> Please note that my patch contains 2 lines of change:
> delete the line 139 of ClientLite.pm.orig, (maybe you have overlooked this
> line)
> and add line 143 of ClientLite.pm
>
> Following is test code:
>
> D:\MoChou>cat bug.pl
> sub foo {
> # ..
> my $DONE = 0;
> eval {
> local $SIG{__DIE__}='DEFAULT';
> local $SIG{__WARN__};
> local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
>
> # ...
> alarm 3;
> # 
> $DONE = 1;
> };
>
> if($@)
> {
> alarm 0;
> # 
> return;
> }
> }
>
> foo();
> print +time, "\n";
> sleep(10);
> print +time, "\n";
>
> D:\MoChou>bug
> 1256143484
> Terminating on signal SIGALRM(14)
>
> D:\MoChou>
>
> 2009/10/20 Philip Gwyn 
>
>
>> On 15-Oct-2009 flw wrote:
>> > Even if there is no defined $@, it also need to alarm(0).
>>
>>
>> Maybe I'm being dense, but I don't see how the eval {} could exit with an
>> alarm
>> still set but $@ not set.  Or is there some magic to alarm() and SIG{ALRM}
>> that
>> I'm unaware of.
>>
>> Also, could you write a test case for this?
>>
>> -Philip
>>
>>
>


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