@@ -757,8 +757,17 @@ def _read(self, expected_cmds, adb_info):
757757 start = time .time ()
758758
759759 while True :
760- msg = self ._transport .bulk_read (constants .MESSAGE_SIZE , adb_info .transport_timeout_s )
761- _LOGGER .debug ("bulk_read(%d): %s" , constants .MESSAGE_SIZE , repr (msg ))
760+ # Read until `constants.MESSAGE_SIZE` bytes are received
761+ msg = bytearray ()
762+ msg_length = constants .MESSAGE_SIZE
763+ while msg_length > 0 :
764+ msg += self ._transport .bulk_read (msg_length , adb_info .transport_timeout_s )
765+ _LOGGER .debug ("bulk_read(%d): %s" , msg_length , repr (msg ))
766+ msg_length -= len (msg )
767+
768+ if time .time () - start > adb_info .read_timeout_s :
769+ raise exceptions .AdbTimeoutError ("Took longer than %f seconds to read %d bytes" % (adb_info .read_timeout_s , constants .MESSAGE_SIZE ))
770+
762771 cmd , arg0 , arg1 , data_length , data_checksum = unpack (msg )
763772 command = constants .WIRE_TO_ID .get (cmd )
764773
@@ -769,7 +778,9 @@ def _read(self, expected_cmds, adb_info):
769778 break
770779
771780 if time .time () - start > adb_info .read_timeout_s :
772- raise exceptions .InvalidCommandError ("Never got one of the expected responses: %s (transport_timeout_s = %d, read_timeout_s = %d" % (expected_cmds , adb_info .transport_timeout_s , adb_info .read_timeout_s ))
781+ raise exceptions .InvalidCommandError ("Never got one of the expected responses: %s (transport_timeout_s = %f, read_timeout_s = %f)" % (expected_cmds , adb_info .transport_timeout_s , adb_info .read_timeout_s ))
782+
783+ data = bytearray ()
773784
774785 if data_length > 0 :
775786 data = bytearray ()
@@ -784,9 +795,6 @@ def _read(self, expected_cmds, adb_info):
784795 if actual_checksum != data_checksum :
785796 raise exceptions .InvalidChecksumError ('Received checksum {0} != {1}' .format (actual_checksum , data_checksum ))
786797
787- else :
788- data = bytearray ()
789-
790798 return command , arg0 , arg1 , bytes (data )
791799
792800 def _read_until (self , expected_cmds , adb_info ):
@@ -833,7 +841,7 @@ def _read_until(self, expected_cmds, adb_info):
833841 break
834842
835843 if time .time () - start > adb_info .read_timeout_s :
836- raise exceptions .InvalidCommandError ("Never got one of the expected responses: %s (transport_timeout_s = %d , read_timeout_s = %d " % (expected_cmds , adb_info .transport_timeout_s , adb_info .read_timeout_s ))
844+ raise exceptions .InvalidCommandError ("Never got one of the expected responses: %s (transport_timeout_s = %f , read_timeout_s = %f) " % (expected_cmds , adb_info .transport_timeout_s , adb_info .read_timeout_s ))
837845
838846 # Ignore CLSE responses to previous commands
839847 # https://github.com/JeffLIrion/adb_shell/pull/14
0 commit comments