From eec773300804f8011b584e6cdfab66ee6678b294 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 3 Jan 2025 15:42:57 +0100 Subject: [PATCH] tools/remote/etherbone/EtherboneIPC/receive_packet: Return 0 in case of TimeoutError. --- litex/tools/remote/etherbone.py | 49 +++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/litex/tools/remote/etherbone.py b/litex/tools/remote/etherbone.py index 760cda532..03225d369 100644 --- a/litex/tools/remote/etherbone.py +++ b/litex/tools/remote/etherbone.py @@ -401,24 +401,31 @@ class EtherboneIPC: 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 \ No newline at end of file