]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
reset() only set current position back to 0. What we want here is truncate(). 203/head
authorDidip Kerabat <didip@didip-osx.local>
Mon, 10 Jan 2011 19:56:28 +0000 (11:56 -0800)
committerDidip Kerabat <didip@didip-osx.local>
Mon, 10 Jan 2011 19:56:28 +0000 (11:56 -0800)
But, per http://stackoverflow.com/questions/4330812/how-do-i-clear-a-stringio-object discussion, creating new StringIO() is cheaper.

tornado/iostream.py

index 8e8adfe2aee07bc38d3554afe83470f7a7b2d956..74c9325c795f880533693c91e5bb07a6dd2914ec 100644 (file)
@@ -338,7 +338,7 @@ class IOStream(object):
                 # of bytes it was able to process.
                 buffered_string = self._write_buffer.getvalue()
                 num_bytes = self.socket.send(buffered_string[:128 * 1024])
-                self._write_buffer.reset()
+                self._write_buffer = StringIO()
                 self._write_buffer.write(buffered_string[num_bytes:])
             except socket.error, e:
                 if e.args[0] in (errno.EWOULDBLOCK, errno.EAGAIN):
@@ -355,7 +355,7 @@ class IOStream(object):
 
     def _consume(self, loc):
         buffered_string = self._read_buffer.getvalue()
-        self._read_buffer.reset()
+        self._read_buffer = StringIO()
         self._read_buffer.write(buffered_string[loc:])
         return buffered_string[:loc]