diff options
author | Guido van Rossum <guido@python.org> | 2000-09-01 03:25:14 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-09-01 03:25:14 (GMT) |
commit | 01fed4d4e6a2d5f4ff85236bb3430cdfef5e4ada (patch) | |
tree | 823bfc7c7ff6d6847ef572f0173129a9f57024f7 | |
parent | b709df381034b6055f03644a8f2eb35cfc6cb411 (diff) | |
download | cpython-01fed4d4e6a2d5f4ff85236bb3430cdfef5e4ada.zip cpython-01fed4d4e6a2d5f4ff85236bb3430cdfef5e4ada.tar.gz cpython-01fed4d4e6a2d5f4ff85236bb3430cdfef5e4ada.tar.bz2 |
In class StreamRequestHandler, make the default buffering for rfile
and wfile class variables (that the instance can also override).
Change the default for rfile to buffered, because that seems to make a
big difference in performance on some platforms.
An anti-patch is needed to revert the effect in CGIHTTPServer.py which
I'll check in momentarily.
-rw-r--r-- | Lib/SocketServer.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py index 5562fb0..a263f8e 100644 --- a/Lib/SocketServer.py +++ b/Lib/SocketServer.py @@ -412,10 +412,20 @@ class StreamRequestHandler(BaseRequestHandler): """Define self.rfile and self.wfile for stream sockets.""" + # Default buffer sizes for rfile, wfile. + # We default rfile to buffered because otherwise it could be + # really slow for large data (a getc() call per byte); we make + # wfile unbuffered because (a) often after a write() we want to + # read and we need to flush the line; (b) big writes to unbuffered + # files are typically optimized by stdio even when big reads + # aren't. + rbufsize = -1 + wbufsize = 0 + def setup(self): self.connection = self.request - self.rfile = self.connection.makefile('rb', 0) - self.wfile = self.connection.makefile('wb', 0) + self.rfile = self.connection.makefile('rb', self.rbufsize) + self.wfile = self.connection.makefile('wb', self.wbufsize) def finish(self): self.wfile.flush() |