[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server - DualModeChannel.py:1.1.2.4.2.4
Shane Hathaway
shane@cvs.zope.org
Thu, 4 Apr 2002 18:09:29 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Server
In directory cvs.zope.org:/tmp/cvs-serv14852
Modified Files:
Tag: Zope3-Server-Branch
DualModeChannel.py
Log Message:
Added an argument to flush() to allow non-blocking flush, and added more comments.
=== Zope3/lib/python/Zope/Server/DualModeChannel.py 1.1.2.4.2.3 => 1.1.2.4.2.4 ===
while len(self.outbuf) >= self.adj.send_bytes:
# Send what we can without blocking.
- # We propogate errors to the application on purpose
- # (to prevent unnecessary work).
+ # We propagate errors to the application on purpose
+ # (to stop the application if the connection closes).
if not self._flush_some():
break
- def flush(self):
- """
- Pauses the application while outbuf is flushed.
- Normally not a good thing to do.
+ def flush(self, block=1):
+ """Sends pending data.
+
+ If block is set, this pauses the application. If it is turned
+ off, only the amount of data that can be sent without blocking
+ is sent.
"""
+ if not block:
+ while self._flush_some():
+ pass
+ return
blocked = 0
try:
while self.outbuf:
- # We propogate errors to the application on purpose.
+ # We propagate errors to the application on purpose.
if not blocked:
self.socket.setblocking(1)
blocked = 1
@@ -205,6 +211,9 @@
#
def _flush_some(self):
+ """Flushes data.
+
+ Returns 1 if some data was sent."""
outbuf = self.outbuf
if outbuf:
chunk = outbuf.get(self.adj.send_bytes)
@@ -252,6 +261,8 @@
if allocate_lock is None:
from thread import allocate_lock
+ # writelock protects all accesses to outbuf, since reads and
+ # writes of buffers in this class need to be serialized.
writelock = allocate_lock()
self._writelock_acquire = writelock.acquire
self._writelock_release = writelock.release
@@ -295,10 +306,10 @@
finally:
self._writelock_release()
- def flush(self):
+ def flush(self, block=1):
self._writelock_acquire()
try:
- DualModeChannel.flush(self)
+ DualModeChannel.flush(self, block)
finally:
self._writelock_release()