diff options
author | Peter Dintelmann <Peter.Dintelmann@Dresdner-Bank.com> | 2005-06-02 15:34:49 +0200 |
---|---|---|
committer | Steve Peters <steve@fisharerojo.org> | 2005-10-05 18:20:54 +0000 |
commit | 2d169392e9b607b54c89d91376e422380d400486 (patch) | |
tree | 6b23e055f108371d89e2151bb87aad508dcb9d78 /ext/IO | |
parent | aa4405f14075248f91be58b81ad56194c9010691 (diff) | |
download | perl-2d169392e9b607b54c89d91376e422380d400486.tar.gz |
proposal [perl #34301]: IO::Socket calls getpeername far too often
Message-ID: <E9A2605289D8D7468B1A21EC24E59D2101852447@naimucx5.muc.allianz>
p4raw-id: //depot/perl@25697
Diffstat (limited to 'ext/IO')
-rw-r--r-- | ext/IO/lib/IO/Socket.pm | 14 | ||||
-rw-r--r-- | ext/IO/lib/IO/Socket/INET.pm | 4 |
2 files changed, 12 insertions, 6 deletions
diff --git a/ext/IO/lib/IO/Socket.pm b/ext/IO/lib/IO/Socket.pm index 4429f2bb3e..46504db209 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 96b49911d8..7d2d538531 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; |