Skip to content

Commit

Permalink
Minor bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcferrill committed Jul 22, 2021
1 parent 0412650 commit 3b61b41
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion chapter10/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def validate(self, silent=False):
elif self.secondary_header:
if self.secondary_sums != self.secondary_checksum:
err = InvalidPacket('Secondary header checksum mismatch!')
elif self.data_length > 524288:
if self.data_length > 524288:
err = InvalidPacket(f'Data length {self.data_length} larger than allowed!')

if err:
Expand Down Expand Up @@ -349,6 +349,10 @@ def __init__(self, data=b'', parent=None, **kwargs):
@classmethod
def from_packet(cls, packet):
"""Helper method to read a message from packet."""

# Exit if we've read all messages.
if hasattr(packet, 'count') and packet.count == len(packet._messages):
raise EOFError

# Exit when we reach the end of the packet body
end = packet.data_length + (packet.secondary_header and 36 or 24)
Expand Down

0 comments on commit 3b61b41

Please sign in to comment.