From b9cc5c58d74145a758eb520c15482ff6366288e3 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 3 Jan 2025 16:37:56 +0100 Subject: [PATCH] tools/litex_client/RemoteClient: Clear socket buffer in case of Timeout. --- litex/tools/litex_client.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/litex/tools/litex_client.py b/litex/tools/litex_client.py index 97800f4c8..66d2f932c 100644 --- a/litex/tools/litex_client.py +++ b/litex/tools/litex_client.py @@ -64,6 +64,15 @@ class RemoteClient(EtherboneIPC, CSRBuilder): del self.socket self.binded = False + def clear_socket_buffer(self): + try: + while True: + data = self.socket.recv(4096) + if not data: + break + except (TimeoutError, socket.error): + pass + def read(self, addr, length=None, burst="incr"): length_int = 1 if length is None else length addr_size = self.csr_bus_address_width // 8 @@ -88,6 +97,7 @@ class RemoteClient(EtherboneIPC, CSRBuilder): # Handle error by returning default values if self.debug: print("Timeout occurred during read. Returning default values.") + self.clear_socket_buffer() return 0 if length is None else [0] * length_int packet = EtherbonePacket(