From d0c09887dc47924cfddad1c19c8f07075a5d3a7c Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Fri, 9 Mar 2018 10:15:22 +0200 Subject: [PATCH] Fix write_to/n mode a bit --- pupy/network/lib/buffer.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pupy/network/lib/buffer.py b/pupy/network/lib/buffer.py index 68ae261a..530f163f 100644 --- a/pupy/network/lib/buffer.py +++ b/pupy/network/lib/buffer.py @@ -324,16 +324,19 @@ class Buffer(object): if not forced_notify and not chunk_size: for idx, chunk in enumerate(self._data): + bofft = 0 + if self._bofft: chunk = chunk[self._bofft:] + bofft = self._bofft self._bofft = 0 lchunk = len(chunk) if n is not None: if total_read + lchunk > n: - self._bofft = lchunk - ( n - total_read ) - chunk = chunk[:self._bofft] + chunk = chunk[:n - total_read] + self._bofft = bofft + n - total_read total_read += len(chunk) @@ -383,7 +386,7 @@ class Buffer(object): if notify and not forced_notify: stream.flush() - return total_write + return total_read, total_write def peek(self, n=-1, view=False): """