From df5342af227ec645ec48a9efe5ab92c5bb8f0b26 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 18 Aug 2018 14:34:29 +0100 Subject: [PATCH] core: split out _internal_receive() This is needed for libssh2. --- mitogen/core.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mitogen/core.py b/mitogen/core.py index c651b85c..9ea7b695 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -1036,6 +1036,16 @@ class Stream(BasicStream): def construct(self): pass + def _internal_receive(self, broker, buf): + if self._input_buf and self._input_buf_len < 128: + self._input_buf[0] += buf + else: + self._input_buf.append(buf) + + self._input_buf_len += len(buf) + while self._receive_one(broker): + pass + def on_receive(self, broker): """Handle the next complete message on the stream. Raise :py:class:`StreamError` on failure.""" @@ -1045,14 +1055,7 @@ class Stream(BasicStream): if not buf: return self.on_disconnect(broker) - if self._input_buf and self._input_buf_len < 128: - self._input_buf[0] += buf - else: - self._input_buf.append(buf) - - self._input_buf_len += len(buf) - while self._receive_one(broker): - pass + self._internal_receive(broker, buf) HEADER_FMT = '>LLLLLL' HEADER_LEN = struct.calcsize(HEADER_FMT)