Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01fed4d

Browse files
committed
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.
1 parent b709df3 commit 01fed4d

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Lib/SocketServer.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,20 @@ class StreamRequestHandler(BaseRequestHandler):
412412

413413
"""Define self.rfile and self.wfile for stream sockets."""
414414

415+
# Default buffer sizes for rfile, wfile.
416+
# We default rfile to buffered because otherwise it could be
417+
# really slow for large data (a getc() call per byte); we make
418+
# wfile unbuffered because (a) often after a write() we want to
419+
# read and we need to flush the line; (b) big writes to unbuffered
420+
# files are typically optimized by stdio even when big reads
421+
# aren't.
422+
rbufsize = -1
423+
wbufsize = 0
424+
415425
def setup(self):
416426
self.connection = self.request
417-
self.rfile = self.connection.makefile('rb', 0)
418-
self.wfile = self.connection.makefile('wb', 0)
427+
self.rfile = self.connection.makefile('rb', self.rbufsize)
428+
self.wfile = self.connection.makefile('wb', self.wbufsize)
419429

420430
def finish(self):
421431
self.wfile.flush()

0 commit comments

Comments
 (0)