summaryrefslogtreecommitdiff
path: root/lib/py/src
diff options
context:
space:
mode:
authorDavid Reiss <dreiss@apache.org>2010-09-02 15:36:00 +0000
committerDavid Reiss <dreiss@apache.org>2010-09-02 15:36:00 +0000
commitc564fa569289240fb210c245b2b1125d759b93e1 (patch)
treecf9b0bc7a52d4c0e4e13be18c3a21f0e9cbc18df /lib/py/src
parent8ede81860c5b6c93645c62e871c213b4188e7162 (diff)
downloadthrift-c564fa569289240fb210c245b2b1125d759b93e1.tar.gz
THRIFT-596. python: Make the TBufferedTransport read buffer size configurable
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@991985 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'lib/py/src')
-rw-r--r--lib/py/src/transport/TTransport.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/py/src/transport/TTransport.py b/lib/py/src/transport/TTransport.py
index 9858bbe21..12e51a9bf 100644
--- a/lib/py/src/transport/TTransport.py
+++ b/lib/py/src/transport/TTransport.py
@@ -129,14 +129,19 @@ class TBufferedTransportFactory:
class TBufferedTransport(TTransportBase,CReadableTransport):
- """Class that wraps another transport and buffers its I/O."""
+ """Class that wraps another transport and buffers its I/O.
+
+ The implementation uses a (configurable) fixed-size read buffer
+ but buffers all writes until a flush is performed.
+ """
DEFAULT_BUFFER = 4096
- def __init__(self, trans):
+ def __init__(self, trans, rbuf_size = DEFAULT_BUFFER):
self.__trans = trans
self.__wbuf = StringIO()
self.__rbuf = StringIO("")
+ self.__rbuf_size = rbuf_size
def isOpen(self):
return self.__trans.isOpen()
@@ -152,7 +157,7 @@ class TBufferedTransport(TTransportBase,CReadableTransport):
if len(ret) != 0:
return ret
- self.__rbuf = StringIO(self.__trans.read(max(sz, self.DEFAULT_BUFFER)))
+ self.__rbuf = StringIO(self.__trans.read(max(sz, self.__rbuf_size)))
return self.__rbuf.read(sz)
def write(self, buf):
@@ -172,9 +177,9 @@ class TBufferedTransport(TTransportBase,CReadableTransport):
def cstringio_refill(self, partialread, reqlen):
retstring = partialread
- if reqlen < self.DEFAULT_BUFFER:
+ if reqlen < self.__rbuf_size:
# try to make a read of as much as we can.
- retstring += self.__trans.read(self.DEFAULT_BUFFER)
+ retstring += self.__trans.read(self.__rbuf_size)
# but make sure we do read reqlen bytes.
if len(retstring) < reqlen: