File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -956,15 +956,29 @@ def _sock_exact_recv(self, bufsize):
956
956
bytes is returned or trigger a timeout exception.
957
957
958
958
:param int bufsize: number of bytes to receive
959
-
959
+ :return: byte array
960
960
"""
961
+ stamp = time .monotonic ()
961
962
if not self ._backwards_compatible_sock :
962
963
# CPython/Socketpool Impl.
963
964
rc = bytearray (bufsize )
964
- self ._sock .recv_into (rc , bufsize )
965
- else : # ESP32SPI Impl.
966
- stamp = time .monotonic ()
965
+ mv = memoryview (rc )
966
+ recv = self ._sock .recv_into (rc , bufsize )
967
+ to_read = bufsize - recv
968
+ assert to_read >= 0
967
969
read_timeout = self .keep_alive
970
+ mv = mv [recv :]
971
+ while to_read > 0 :
972
+ recv = self ._sock .recv_into (mv , to_read )
973
+ to_read -= recv
974
+ mv = mv [recv :]
975
+ if time .monotonic () - stamp > read_timeout :
976
+ raise MMQTTException (
977
+ "Unable to receive {} bytes within {} seconds." .format (
978
+ to_read , read_timeout
979
+ )
980
+ )
981
+ else : # ESP32SPI Impl.
968
982
# This will timeout with socket timeout (not keepalive timeout)
969
983
rc = self ._sock .recv (bufsize )
970
984
if not rc :
You can’t perform that action at this time.
0 commit comments