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.lampre...@proxmox.com>
Cc: Martin Verges <martin.ver...@croit.io>
---
 PVE/Status/Graphite.pm | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/PVE/Status/Graphite.pm b/PVE/Status/Graphite.pm
index fdd4ff4c..8afadb53 100644
--- a/PVE/Status/Graphite.pm
+++ b/PVE/Status/Graphite.pm
@@ -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");
 
-- 
2.20.1


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to