[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server - DualModeChannel.py:1.1.2.4.2.5
Shane Hathaway
shane@cvs.zope.org
Fri, 5 Apr 2002 17:50:08 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Server
In directory cvs.zope.org:/tmp/cvs-serv20800
Modified Files:
Tag: Zope3-Server-Branch
DualModeChannel.py
Log Message:
Simplified the DualModeChannel constructor, since the server attribute is not needed. Made sure data is written only when the socket is connected. Fixed close_when_done(), which was inexplicably pulling the async thread trigger in async mode.
=== Zope3/lib/python/Zope/Server/DualModeChannel.py 1.1.2.4.2.4 => 1.1.2.4.2.5 ===
async_mode = 1
- def __init__(self, server, conn, addr, adj=None, socket_map=None):
- self.server = server
+ def __init__(self, conn, addr, adj=None, socket_map=None):
self.addr = addr
if adj is None:
adj = default_adj
@@ -215,7 +214,7 @@
Returns 1 if some data was sent."""
outbuf = self.outbuf
- if outbuf:
+ if outbuf and self.connected:
chunk = outbuf.get(self.adj.send_bytes)
num_sent = self.send(chunk)
if num_sent:
@@ -224,19 +223,16 @@
return 0
def close_when_done(self):
- if self.async_mode:
- self.will_close = 1
- self.pull_trigger()
+ # We might be able close immediately.
+ while self._flush_some():
+ pass
+ if not self.outbuf:
+ # Quick exit.
+ self.close()
else:
- # We might be able close immediately.
- while self._flush_some():
- pass
- if not self.outbuf:
- # Quick exit.
- self.close()
- else:
- # Wait until outbuf is flushed.
- self.will_close = 1
+ # Wait until outbuf is flushed.
+ self.will_close = 1
+ if not self.async_mode:
self.async_mode = 1
self.pull_trigger()
@@ -256,7 +252,7 @@
__implements__ = asyncore.dispatcher.__implements__
- def __init__(self, server, conn, addr, adj=None, socket_map=None):
+ def __init__(self, conn, addr, adj=None, socket_map=None):
global allocate_lock
if allocate_lock is None:
from thread import allocate_lock
@@ -267,7 +263,7 @@
self._writelock_acquire = writelock.acquire
self._writelock_release = writelock.release
self._writelock_locked = writelock.locked
- DualModeChannel.__init__(self, server, conn, addr, adj, socket_map)
+ DualModeChannel.__init__(self, conn, addr, adj, socket_map)
#
# ASYNCHRONOUS METHODS