]> git.proxmox.com Git - pve-manager-legacy.git/commitdiff
status/graphite: just use setsockopt to set timeouts
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 7 Nov 2019 15:27:34 +0000 (16:27 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 7 Nov 2019 15:27:50 +0000 (16:27 +0100)
after rethinking this it felt weird, sockets already can to this
themself, so I checked out the IO::Socket::Timeout module, and yeah,
it's just a OOP wrapper for this, hiding the "scary" struct pack.

So instead of adding that as dependency lets do it ourself.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/Status/Graphite.pm

index fdd4ff4c8743eac26448bd7ebf24a878214b5315..8afadb5362ba884baeae74180be641e8f812e9f0 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 use IO::Socket::IP;
-use IO::Socket::Timeout;
+use Socket qw(SOL_SOCKET SO_SNDTIMEO SO_RCVTIMEO);
 
 use PVE::Status::Plugin;
 use PVE::JSONSchema;
@@ -105,9 +105,10 @@ sub write_graphite_hash {
     ) || die "couldn't create carbon socket [$host]:$port - $@\n";
 
     if ( $proto eq 'tcp' ) {
-       IO::Socket::Timeout->enable_timeouts_on($carbon_socket);
-       $carbon_socket->read_timeout($timeout);
-       $carbon_socket->write_timeout($timeout);
+       # seconds and µs
+       my $timeout_struct = pack( 'l!l!', $timeout, 0);
+       setsockopt($carbon_socket, SOL_SOCKET, SO_SNDTIMEO, $timeout_struct);
+       setsockopt($carbon_socket, SOL_SOCKET, SO_RCVTIMEO, $timeout_struct);
     }
     write_graphite($carbon_socket, $d, $ctime, $path.".$object");