From: Peter Dintelmann Date: Thu, 2 Jun 2005 13:34:49 +0000 (+0200) Subject: proposal [perl #34301]: IO::Socket calls getpeername far too often X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2d169392e9b607b54c89d91376e422380d400486;p=p5sagit%2Fp5-mst-13.2.git proposal [perl #34301]: IO::Socket calls getpeername far too often Message-ID: p4raw-id: //depot/perl@25697 --- diff --git a/ext/IO/lib/IO/Socket.pm b/ext/IO/lib/IO/Socket.pm index 4429f2b..46504db 100644 --- a/ext/IO/lib/IO/Socket.pm +++ b/ext/IO/lib/IO/Socket.pm @@ -23,7 +23,7 @@ require IO::Socket::UNIX if ($^O ne 'epoc' && $^O ne 'symbian'); @ISA = qw(IO::Handle); -$VERSION = "1.29"; +$VERSION = "1.29_01"; @EXPORT_OK = qw(sockatmark); @@ -141,6 +141,13 @@ sub connect { $err ? undef : $sock; } +sub close { + @_ == 1 or croak 'usage: $sock->close()'; + my $sock = shift; + ${*$sock}{'io_socket_peername'} = undef; + $sock->SUPER::close(); +} + sub bind { @_ == 2 or croak 'usage: $sock->bind(NAME)'; my $sock = shift; @@ -195,9 +202,7 @@ sub sockname { sub peername { @_ == 1 or croak 'usage: $sock->peername()'; my($sock) = @_; - getpeername($sock) - || ${*$sock}{'io_socket_peername'} - || undef; + ${*$sock}{'io_socket_peername'} ||= getpeername($sock); } sub connected { @@ -239,6 +244,7 @@ sub recv { sub shutdown { @_ == 2 or croak 'usage: $sock->shutdown(HOW)'; my($sock, $how) = @_; + ${*$sock}{'io_socket_peername'} = undef; shutdown($sock, $how); } diff --git a/ext/IO/lib/IO/Socket/INET.pm b/ext/IO/lib/IO/Socket/INET.pm index 96b4991..7d2d538 100644 --- a/ext/IO/lib/IO/Socket/INET.pm +++ b/ext/IO/lib/IO/Socket/INET.pm @@ -15,7 +15,7 @@ use Exporter; use Errno; @ISA = qw(IO::Socket); -$VERSION = "1.29"; +$VERSION = "1.29_01"; my $EINVAL = exists(&Errno::EINVAL) ? Errno::EINVAL() : 1; @@ -81,7 +81,7 @@ sub _error { local($!); my $title = ref($sock).": "; $@ = join("", $_[0] =~ /^$title/ ? "" : $title, @_); - close($sock) + $sock->close() if(defined fileno($sock)); } $! = $err;