From: Didip Kerabat Date: Mon, 10 Jan 2011 19:56:28 +0000 (-0800) Subject: reset() only set current position back to 0. What we want here is truncate(). X-Git-Tag: v1.2.0~46^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bba5a45c3f3e5d4bc24e0ba8e30f4a55b5468b7f;p=thirdparty%2Ftornado.git reset() only set current position back to 0. What we want here is truncate(). But, per http://stackoverflow.com/questions/4330812/how-do-i-clear-a-stringio-object discussion, creating new StringIO() is cheaper. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index 8e8adfe2a..74c9325c7 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -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]