develooper Front page | perl.perl5.porters | Postings from October 2005

[perl #34301] IO::Socket calls getpeername far too often

From:
Steve Peters via RT
Date:
October 5, 2005 11:48
Subject:
[perl #34301] IO::Socket calls getpeername far too often
Message ID:
rt-3.0.11-34301-122229.1.91539135266765@perl.org
> [dint - Thu Jun 02 04:35:41 2005]:
> 
>     This is a proposal for bug #34301, "IO::Socket calls getpeername
>     far too often".
> 
> > CC: bmc@snort.org
> > Subject: IO::Socket calls getpeername far too often
> > Date: Tue, 1 Mar 2005 11:33:10 -0500
> > To: perlbug@perl.org
> > From: Brian Caswell <bmc@hacked.sfeng.sourcefire.com>
> 
>     [snip]
> 
> > The peername sub can use a cache of the peername, but it only uses 
the
> > cache if getpeername fails. Shouldn't it use the cache first, and 
only
> > look up the name if the cache doesn't exist?
> 
>     The patch below introduces this behaviour. The peername() method 
>     now caches the peername retrieved from getpeername(). Both close()
>     and shutdown() invalidate the cache.
>     A new method close() is introduced in IO::Socket to this end and
>     close($sock) in IO::Socket::INET is replaced with $sock->close() 
to
>     enforce the cache invalidation.
>     I am not sure if all this should really be done. Can someone 
please
>     carefully re-think it?
> 
> > The send sub currently calls getpeername once or twice. If the peer 
wasn't
> > passed in as an arguement, send calls peername. 
> 
>     this is cached now
> 
> > Then later, send calls
> > getpeername to decide if it should pass the peer to Socket's send. 
If the
> > send is successful, then the peername is cached, but the cache 
isn't used
> > in later sends.
> 
>     The purpose of this call to getpeername() is not to find out the 
actual
>     peername but to know if the socket is still connected. This is 
needed
> for
>     the subsequent call to Socket's send(). I therefore think that 
this call
>     to getpeername() cannot be avoided.
> 
> > I tried making the above changes to IO::Socket in perl-current 
(rsynced
> from
> > rsync://ftp.linux.activestate.com/perl-current/ this morning). The 
change
> > worked fine for UDP, but t/io_udp.t hangs at test 6.
> 
> 

Thanks!  This has been applied as change #25697.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About