Hi All,
   I'm really new to perl and as usual in our business world I have to be 
productive while I still learn.

   I'm running checks in IOT over REST API's and I saw that my script using the 
LWP::UserAgent::Determined is generating loads of useless syn in case of 
outages:
If I have a small glitch on the connection of a few minutes, I start sending 
thousands of SYN's as my devices are unreachable and every attempt generates 6 
retries (only 5 are visible as the $ua->timeout is set to 60)...

   I searched a few hours and I figured out it was a unix socket feature.

   A few hours later, I found a topic on this website concerning the socket 
settings (https://www.nntp.perl.org/group/perl.libwww/2005/12/msg6480.html). I 
tried and, naturally, it is no longer working, as the 
LWP::UserAgent(::Determined) is now relying on IO::Socket, as I finally read 
elsewhere.

I understand that I can play with the $ua->timeout attribute to achieve the 
same, but that would also affect long running request and potentially have 
devastating consequences (I would need to reduce the timeout to 14seconds 
instead of 60 to achieve the same effect as SYNCNT 2).

   Now, I tried to implement the same method as in the post above with the 
IO::Socket, but it doesn't work. I can't find anything similar to "Implementor" 
(I understand what I want to achieve but my perl grammar is way too basic to 
know how to):

use IO::Socket;

{
package MySocket;
use base 'IO::Socket';
#IO::Socket::implementor(AF_INET => __PACKAGE__); <<<<<<????

package MySocket::INET;
use base 'IO::Socket::INET';
use Socket qw(IPPROTO_TCP TCP_SYNCNT);

    sub new {
       my $class = shift;
       my $sock = $class->SUPER::new(@_);
       if ($sock) {
           setsockopt($sock, IPPROTO_TCP, TCP_SYNCNT, 2);
           }
       return $sock;
      }
}

I don't know how I could perform some sort of closure so that in my context the 
IO::Socket::INET->new() becomes my function, and therefore, when I open an HTTP 
socket it would have the features I have set.

I believe it is pretty common that people want to modify the socket setting 
despite using high layer abstractions... Maybe you can direct me to some 
documentation?

Thanks a lot!

Regards,
Bernard C

Reply via email to