summaryrefslogtreecommitdiffstats
path: root/lib/SNMP_Session.pm
diff options
context:
space:
mode:
authorTobi Oetiker <tobi@oetiker.ch>2011-08-23 15:53:40 +0200
committerTobi Oetiker <tobi@oetiker.ch>2011-08-23 15:53:40 +0200
commit7bcda72c21f3d1d28760427455b3b1c9b2f48b44 (patch)
treecae918862a5e5a0573e4046cc49c0a34e8504561 /lib/SNMP_Session.pm
parent454e8ff564da151b1ad8bb56140a582ea827a4f9 (diff)
downloadsmokeping-7bcda72c21f3d1d28760427455b3b1c9b2f48b44.tar.gz
smokeping-7bcda72c21f3d1d28760427455b3b1c9b2f48b44.tar.xz
updated to SNMP_Session 1.13
Diffstat (limited to 'lib/SNMP_Session.pm')
-rw-r--r--lib/SNMP_Session.pm23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/SNMP_Session.pm b/lib/SNMP_Session.pm
index 8521a52..4b9ccf9 100644
--- a/lib/SNMP_Session.pm
+++ b/lib/SNMP_Session.pm
@@ -62,7 +62,7 @@ sub map_table_start_end ($$$$$$);
sub index_compare ($$);
sub oid_diff ($$);
-$VERSION = '1.12';
+$VERSION = '1.13';
@ISA = qw(Exporter);
@@ -153,7 +153,11 @@ BEGIN {
eval 'local $SIG{__DIE__};local $SIG{__WARN__};$dont_wait_flags = MSG_DONTWAIT();';
}
-my $the_socket;
+### Cache for reusable sockets. This is indexed by socket (address)
+### family, so that we don't try to reuse an IPv4 socket for IPv6 or
+### vice versa.
+###
+my %the_socket = ();
$SNMP_Session::errmsg = '';
$SNMP_Session::suppress_warnings = 0;
@@ -633,15 +637,15 @@ sub open {
$remote_addr = inet_aton ($remote_hostname)
or return $this->error_return ("can't resolve \"$remote_hostname\" to IP address");
}
- if ($SNMP_Session::recycle_socket && defined $the_socket) {
- $socket = $the_socket;
+ if ($SNMP_Session::recycle_socket && exists $the_socket{$sockfamily}) {
+ $socket = $the_socket{$sockfamily};
} else {
$socket = IO::Socket::INET->new(Proto => 17,
Type => SOCK_DGRAM,
LocalAddr => $local_hostname,
LocalPort => $local_port)
|| return $this->error_return ("creating socket: $!");
- $the_socket = $socket
+ $the_socket{$sockfamily} = $socket
if $SNMP_Session::recycle_socket;
}
$remote_addr = pack_sockaddr_in ($port, $remote_addr)
@@ -662,8 +666,8 @@ sub open {
return $this->error_return ("can't resolve \"$remote_hostname\" to IPv6 address");
}
- if ($SNMP_Session::recycle_socket && defined $the_socket) {
- $socket = $the_socket;
+ if ($SNMP_Session::recycle_socket && exists $the_socket{$sockfamily}) {
+ $socket = $the_socket{$sockfamily};
} elsif ($sockfamily == AF_INET) {
$socket = IO::Socket::INET->new(Proto => 17,
Type => SOCK_DGRAM,
@@ -676,7 +680,7 @@ sub open {
LocalAddr => $local_hostname,
LocalPort => $local_port)
|| return $this->error_return ("creating socket: $!");
- $the_socket = $socket
+ $the_socket{$sockfamily} = $socket
if $SNMP_Session::recycle_socket;
}
}
@@ -728,7 +732,8 @@ sub close {
my($this) = shift;
## Avoid closing the socket if it may be shared with other session
## objects.
- if (! defined $the_socket || $this->sock ne $the_socket) {
+ if (! exists $the_socket{$this->{sockfamily}}
+ or $this->sock ne $the_socket{$this->{sockfamily}}) {
close ($this->sock) || $this->error ("close: $!");
}
}