From 3bdbba04d2a9fa8f1efca41c307078d0af143fa2 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 29 Oct 2020 15:17:25 -0700 Subject: [PATCH 1/3] Don't wait for the timeout in recv when we've received some bytes --- adafruit_esp32spi/adafruit_esp32spi_socket.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_esp32spi/adafruit_esp32spi_socket.py b/adafruit_esp32spi/adafruit_esp32spi_socket.py index 99d73f0..517b01d 100644 --- a/adafruit_esp32spi/adafruit_esp32spi_socket.py +++ b/adafruit_esp32spi/adafruit_esp32spi_socket.py @@ -105,7 +105,8 @@ def readline(self): return firstline def recv(self, bufsize=0): - """Reads some bytes from the connected remote address. + """Reads some bytes from the connected remote address. Will only return + an empty string after the configured timeout. :param int bufsize: maximum number of bytes to receive """ # print("Socket read", bufsize) @@ -134,6 +135,10 @@ def recv(self, bufsize=0): received.append(recv) to_read -= len(recv) gc.collect() + elif received: + # We've received some bytes but no more are available. So return + # what we have. + break if self._timeout > 0 and time.monotonic() - stamp > self._timeout: break # print(received) From ea5f86b3bec1b84bc830eab5b083ba7a4e410000 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 29 Oct 2020 15:22:42 -0700 Subject: [PATCH 2/3] Improve doc whitespace --- adafruit_esp32spi/adafruit_esp32spi_socket.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_esp32spi/adafruit_esp32spi_socket.py b/adafruit_esp32spi/adafruit_esp32spi_socket.py index 517b01d..d83470c 100644 --- a/adafruit_esp32spi/adafruit_esp32spi_socket.py +++ b/adafruit_esp32spi/adafruit_esp32spi_socket.py @@ -107,7 +107,8 @@ def readline(self): def recv(self, bufsize=0): """Reads some bytes from the connected remote address. Will only return an empty string after the configured timeout. - :param int bufsize: maximum number of bytes to receive + + :param int bufsize: maximum number of bytes to receive """ # print("Socket read", bufsize) if bufsize == 0: # read as much as we can at the moment From 98f31adcf37573f87c5bd21d2ec3c8e7fae53471 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 29 Oct 2020 15:25:38 -0700 Subject: [PATCH 3/3] Pre-commit --- adafruit_esp32spi/adafruit_esp32spi_socket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_esp32spi/adafruit_esp32spi_socket.py b/adafruit_esp32spi/adafruit_esp32spi_socket.py index d83470c..8c5b66b 100644 --- a/adafruit_esp32spi/adafruit_esp32spi_socket.py +++ b/adafruit_esp32spi/adafruit_esp32spi_socket.py @@ -107,7 +107,7 @@ def readline(self): def recv(self, bufsize=0): """Reads some bytes from the connected remote address. Will only return an empty string after the configured timeout. - + :param int bufsize: maximum number of bytes to receive """ # print("Socket read", bufsize)