From 3d2beb24fd7c0b437147159a401260a3425e59ba Mon Sep 17 00:00:00 2001 From: maralla Date: Thu, 28 Aug 2014 16:48:38 +0800 Subject: [PATCH] once reading in cybin may not get correct length of data --- thriftpy/protocol/cybin/binbuf.pxi | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/thriftpy/protocol/cybin/binbuf.pxi b/thriftpy/protocol/cybin/binbuf.pxi index 65fbc37..004bf6e 100644 --- a/thriftpy/protocol/cybin/binbuf.pxi +++ b/thriftpy/protocol/cybin/binbuf.pxi @@ -79,15 +79,21 @@ cdef class BinaryRW(object): if self.rbuf.data_size < size: cap = self.rbuf.buf_size - self.rbuf.data_size new_data = self.trans._read(cap) + new_data_len = len(new_data) + + while new_data_len < size - self.rbuf.data_size: + data = self.trans._read(cap - new_data_len) + new_data += data + new_data_len += len(data) # buf + buf_size >= buf + cur + data_size + new_data_len --> # buf_size - data_size >= cur + new_data_len --> # cap - cur >= new_data_len - if cap - self.rbuf.cur < len(new_data): + if cap - self.rbuf.cur < new_data_len: self.rbuf.move_to_start() memcpy(self.rbuf.buf + self.rbuf.cur + self.rbuf.data_size, - new_data, len(new_data)) - self.rbuf.data_size += len(new_data) + new_data, new_data_len) + self.rbuf.data_size += new_data_len cdef read_byte(self, byte *ret): self.ensure_rbuf(1)