Skip to content

Commit

Permalink
tools/remote/etherbone/EtherboneIPC/receive_packet: Return 0 in case …
Browse files Browse the repository at this point in the history
…of TimeoutError.
  • Loading branch information
enjoy-digital committed Jan 3, 2025
1 parent e3dcfbd commit eec7733
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions litex/tools/remote/etherbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,24 +401,31 @@ def send_packet(self, socket, packet):
def receive_packet(self, socket, addr_size):
assert addr_size in [1, 2, 4, 8]
header_length = etherbone_packet_header_length + etherbone_record_header_length
packet = bytes()
while len(packet) < header_length:
chunk = socket.recv(header_length - len(packet))
if len(chunk) == 0:
return 0
else:
packet += chunk
wcount, rcount = struct.unpack(">BB", packet[header_length-2:])
counts = wcount + rcount
packet_size = header_length
if wcount != 0:
packet_size += 4 * (wcount ) + addr_size
if rcount != 0:
packet_size += (rcount + 1 ) * addr_size
while len(packet) < packet_size:
chunk = socket.recv(packet_size - len(packet))
if len(chunk) == 0:
return 0
else:
packet += chunk
return packet
packet = bytes()
try:
while len(packet) < header_length:
chunk = socket.recv(header_length - len(packet))
if len(chunk) == 0:
return 0
else:
packet += chunk

wcount, rcount = struct.unpack(">BB", packet[header_length - 2:])
counts = wcount + rcount
packet_size = header_length
if wcount != 0:
packet_size += 4 * (wcount) + addr_size
if rcount != 0:
packet_size += (rcount + 1) * addr_size

while len(packet) < packet_size:
chunk = socket.recv(packet_size - len(packet))
if len(chunk) == 0:
return 0
else:
packet += chunk

return packet

except TimeoutError:
return 0

0 comments on commit eec7733

Please sign in to comment.