tools/remote/etherbone/EtherboneIPC/receive_packet: Return 0 in case of TimeoutError.

This commit is contained in:
Florent Kermarrec 2025-01-03 15:42:57 +01:00
parent e3dcfbde60
commit eec7733008
1 changed files with 28 additions and 21 deletions

View File

@ -402,12 +402,14 @@ class EtherboneIPC:
assert addr_size in [1, 2, 4, 8]
header_length = etherbone_packet_header_length + etherbone_record_header_length
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
@ -415,10 +417,15 @@ class EtherboneIPC:
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