I have a very strange scenario. I have a Perl application that receives input from several connections (sockets and pipes). Than I am forwarding the message to a pre-defined destinations (sockets are already opened).
see code example:
our %openSockets;
sub forward_message{
my ($message,$ip,$port,$proto) = @_;
my $key = "$ip:$port:$proto";
my $socket = $openSockets{$key};
unless ($socket && $socket->connected()){
$|=1;#Setting autoflush
$socket = new IO::Socket::INET6(
PeerAddr => $ip,
PeerPort => $port,
Proto => $proto
) || die "Can't create socket [$key]";
$openSockets{$key} = $socket;
}
#autoflush $sock 1;
$socket->say($message);
#$socket->flush();
}
The program works fine on the first few minutes but than - for some reason autoflush stop working and the socket starts to buffer. The socket starts to send chunks of ~1500 bytes.
Currently what seems to help is manually calling the flush function (see commented inline). Can anyone explain why autoflush stop working suddenly after few minutes? Is calling manually to flush a valid and only solution?
FYI - i run strace on the process and made sure its the process that writes the ~1500 bytes chunks (This is not the interface driver that decides to buffer it)
More info if needed: Platfom: Linux Perl version: 5.16 Module Version: 2.69 (INET6) | 1.34 (Socket)
I found a workaround. Not sure it will work as expected if you are using Perl-Threads, but for my small application it works.
Manually calling flush will send the message if autoflush failed to do so.
I will open a ticket the the CPAN IO group