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):
956956 bytes is returned or trigger a timeout exception.
957957
958958 :param int bufsize: number of bytes to receive
959-
959+ :return: byte array
960960 """
961+ stamp = time .monotonic ()
961962 if not self ._backwards_compatible_sock :
962963 # CPython/Socketpool Impl.
963964 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
967969 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.
968982 # This will timeout with socket timeout (not keepalive timeout)
969983 rc = self ._sock .recv (bufsize )
970984 if not rc :
You can’t perform that action at this time.
0 commit comments