summaryrefslogtreecommitdiff
path: root/Lib/SimpleXMLRPCServer.py
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2005-12-04 15:36:57 +0000
committerAndrew M. Kuchling <amk@amk.ca>2005-12-04 15:36:57 +0000
commite63fde72f397385e09000e243e16eda7e01e3242 (patch)
tree79a29fce679a714d685f4d8fc68ae424d39c55b7 /Lib/SimpleXMLRPCServer.py
parent3a97605500919ceeff8c6cd2dd7d352baa1142d8 (diff)
downloadcpython-git-e63fde72f397385e09000e243e16eda7e01e3242.tar.gz
[Bug #792570] Under Windows, socket.read() seems to run into trouble when
asked to read tens of megabytes of data. On my Mac, it hits MemoryErrors when reading around 15Mb in one chunk. The fix is to read the body in several parts, not as one big piece. It would be nice to fix the underlying socket.read() problem, too. 2.4 bugfix candidate.
Diffstat (limited to 'Lib/SimpleXMLRPCServer.py')
-rw-r--r--Lib/SimpleXMLRPCServer.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/SimpleXMLRPCServer.py b/Lib/SimpleXMLRPCServer.py
index ae06bda354..f9999f6d8c 100644
--- a/Lib/SimpleXMLRPCServer.py
+++ b/Lib/SimpleXMLRPCServer.py
@@ -422,8 +422,19 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""
try:
- # get arguments
- data = self.rfile.read(int(self.headers["content-length"]))
+ # Get arguments by reading body of request.
+ # We read this in chunks to avoid straining
+ # socket.read(); around the 10 or 15Mb mark, some platforms
+ # begin to have problems (bug #792570).
+ max_chunk_size = 10*1024*1024
+ size_remaining = int(self.headers["content-length"])
+ L = []
+ while size_remaining:
+ chunk_size = min(size_remaining, max_chunk_size)
+ L.append(self.rfile.read(chunk_size))
+ size_remaining -= len(L[-1])
+ data = ''.join(L)
+
# In previous versions of SimpleXMLRPCServer, _dispatch
# could be overridden in this class, instead of in
# SimpleXMLRPCDispatcher. To maintain backwards compatibility,