Subject: | Perl socket (IO::Socket::INET6) is not autoflushing |
Date: | Wed, 14 Feb 2018 10:09:24 +0200 |
To: | bug-IO [...] rt.cpan.org |
From: | Yaniv German <yaniv.german [...] gmail.com> |
Hi
Following a post I posted in stack overflow (
https://stackoverflow.com/questions/48742557/perl-socket-iosocketinet6-is-not-autoflushing
)
I am using IO::Socket::INET6 (Perl).
Versions:
Linux Perl version: 5.16 Module Version: 2.69 (INET6) | 1.34 (Socket)
I am using this base code:
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 "forward_message" function is called every 1-5 seconds based on input
my application receives and send a message to a destination
(ip|port|protocol Trio)
At first the message are sent individually but after some time the messages
are buffered and sent in big chunks
The bug occurs when I try to send messages via UDP (so this is not a TCP
buffering)
As you can see in the attached code, I was trying all kind of stuff i found
online.
Finally - what that "solved" the problem is when I called "$socket->flush();
"
This ensure the message being sent - avoiding auto flush
Important to say - this is not a threaded application. So calling manually
to flush will work on this case
Message body is not shown because it is too large.