From 2a7b43d853fb5a858fab7854f6bd5d0cc823f494 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 7 Nov 2019 20:57:55 -0800 Subject: [PATCH] bugfix: return empty bytes immediately if read length is 0 --- libp2p/security/secio/transport.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libp2p/security/secio/transport.py b/libp2p/security/secio/transport.py index 6a4c867..cf807bf 100644 --- a/libp2p/security/secio/transport.py +++ b/libp2p/security/secio/transport.py @@ -111,6 +111,9 @@ class SecureSession(BaseSession): self.high_watermark = len(msg) async def read(self, n: int = -1) -> bytes: + if n == 0: + return bytes() + data_from_buffer = self._drain(n) if len(data_from_buffer) > 0: return data_from_buffer