Changeset d6535bd in ammosreader for ammosreader/AmmosSocketSource.py
- Timestamp:
- 05/28/23 15:00:01 (2 years ago)
- Branches:
- AmmosSource
- Children:
- 90cd378
- Parents:
- 1de11fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ammosreader/AmmosSocketSource.py
r1de11fa rd6535bd 11 11 12 12 def read_bytes(self, bytes_to_read): 13 """ 14 I read bytes_to_read bytes from my socket. Incomplete reads get discarded. 15 16 :param bytes_to_read: the number of bytes to read 17 :type bytes_to_read: int 18 19 :return: the complete byte string or None if not all the bytes are read 20 :rtype: bytes 21 """ 22 23 assert bytes_to_read > 0 13 24 byte_array = [] 14 25 logger.info("Start reading bytes from socket") 15 26 try: 16 while len(b ''.join(byte_array)) < bytes_to_read:17 logger.info("Remaining Bytes: %s", bytes_to_read - len(b ''.join(byte_array)))18 self.source.settimeout( 5)19 new_bytes = self.source.recv(bytes_to_read - len(b ''.join(byte_array)), socket.MSG_WAITALL)27 while len(byte_array) < bytes_to_read: 28 logger.info("Remaining Bytes: %s", bytes_to_read - len(byte_array)) 29 self.source.settimeout(self.timeout) 30 new_bytes = self.source.recv(bytes_to_read - len(byte_array), socket.MSG_WAITALL) 20 31 21 32 if not new_bytes: 22 33 raise TimeoutError("Socket timed out while reading data") 23 logger.info("Got %s bytes of %s remaining", len(new_bytes), bytes_to_read - len(b ''.join(byte_array)))34 logger.info("Got %s bytes of %s remaining", len(new_bytes), bytes_to_read - len(byte_array)) 24 35 byte_array.append(new_bytes) 25 print(byte_array)26 36 except TimeoutError: 27 37 logger.info("Timeout error while reading from socket")
Note:
See TracChangeset
for help on using the changeset viewer.