From: <cg...@us...> - 2008-01-14 18:40:56
|
Revision: 4027 http://jython.svn.sourceforge.net/jython/?rev=4027&view=rev Author: cgroves Date: 2008-01-14 10:40:55 -0800 (Mon, 14 Jan 2008) Log Message: ----------- Jython can't make a channel till it connects either through listen, accept or connect, and since the channel is used as fileno, it doesn't have a fileno till it connects. asyncore is expecting fileno to always be defined, so it adds None to the map as the file descriptor on unconnected Jython sockets. This delays adding fileno to the map until a connection is made. Modified Paths: -------------- trunk/jython/Lib/asyncore.py Modified: trunk/jython/Lib/asyncore.py =================================================================== --- trunk/jython/Lib/asyncore.py 2008-01-14 18:39:02 UTC (rev 4026) +++ trunk/jython/Lib/asyncore.py 2008-01-14 18:40:55 UTC (rev 4027) @@ -235,7 +235,13 @@ def add_channel(self, map=None): #self.log_info('adding channel %s' % self) if map is None: - map = socket_map + if hasattr(self, '_map'): + map = self._map + del self._map + else: + map = socket_map + if not hasattr(self, '_fileno'): + self._fileno = self.socket.fileno() map[self._fileno] = self def del_channel(self, map=None): @@ -250,14 +256,14 @@ self.family_and_type = family, type self.socket = socket.socket(family, type) self.socket.setblocking(0) - self._fileno = self.socket.fileno() - self.add_channel() - + def set_socket(self, sock, map=None): self.socket = sock ## self.__dict__['socket'] = sock - self._fileno = sock.fileno() - self.add_channel(map) + if sock.fileno(): + self.add_channel(map) + else: + self._map = map def set_reuse_addr(self): # try to re-use a server port if possible @@ -296,7 +302,9 @@ self.accepting = 1 if os.name == 'nt' and num > 5: num = 1 - return self.socket.listen(num) + ret = self.socket.listen(num) + self.add_channel() + return ret def bind(self, addr): self.addr = addr @@ -309,6 +317,7 @@ if err in (EINPROGRESS, EALREADY, EWOULDBLOCK): return if err in (0, EISCONN): + self.add_channel() self.addr = address self.connected = 1 self.handle_connect() @@ -319,6 +328,7 @@ # XXX can return either an address pair or None try: conn, addr = self.socket.accept() + self.add_channel() return conn, addr except socket.error, why: if why[0] == EWOULDBLOCK: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |