Changeset d6535bd in ammosreader for ammosreader/AmmosSocketSource.py


Ignore:
Timestamp:
05/28/23 15:00:01 (2 years ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
AmmosSource
Children:
90cd378
Parents:
1de11fa
Message:

more refactoring to clean up superfluous classes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ammosreader/AmmosSocketSource.py

    r1de11fa rd6535bd  
    1111
    1212    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
    1324        byte_array = []
    1425        logger.info("Start reading bytes from socket")
    1526        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)
    2031
    2132                if not new_bytes:
    2233                    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))
    2435                byte_array.append(new_bytes)
    25                 print(byte_array)
    2636        except TimeoutError:
    2737            logger.info("Timeout error while reading from socket")
Note: See TracChangeset for help on using the changeset viewer.