[Python-checkins] CVS: python/dist/src/Lib asyncore.py,1.27,1.28

Jeremy Hylton jhylton@users.sourceforge.net
2001年12月14日 08:15:13 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv12555
Modified Files:
	asyncore.py 
Log Message:
Partial fix for problem in SF buf #487458
Rev 1.20 introduced a call to getpeername() in the dispatcher
constructor. This only works for a connected socket. Apparently
earlier versions of the code worked with un-connected sockets, e.g. a
listening socket.
It's not clear that the code is supposed to accept these sockets,
because it sets self.connected = 1 when passed a socket. But it's
also not clear that it should be a fatal error to pass a listening
socket.
The solution, for now, is to put a try/except around the getpeername()
call and continue if it fails. The self.addr attribute is used
primarily (only?) to produce a nice repr for the object, so it hardly
matters. If there is a real error on a connected socket, it's likely
that subsequent calls will fail too.
Index: asyncore.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/asyncore.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** asyncore.py	2001年10月30日 14:16:17	1.27
--- asyncore.py	2001年12月14日 16:15:11	1.28
***************
*** 213,217 ****
 self.socket.setblocking (0)
 self.connected = 1
! self.addr = sock.getpeername()
 else:
 self.socket = None
--- 213,223 ----
 self.socket.setblocking (0)
 self.connected = 1
! # XXX Does the constructor require that the socket passed
! # be connected?
! try:
! self.addr = sock.getpeername()
! except socket.error:
! # The addr isn't crucial
! pass
 else:
 self.socket = None

AltStyle によって変換されたページ (->オリジナル) /