Skip to content

Commit

Permalink
tools/litex_client/RemoteClient: Clear socket buffer in case of Timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Jan 3, 2025
1 parent fc529dc commit b9cc5c5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions litex/tools/litex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ def close(self):
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
Expand All @@ -88,6 +97,7 @@ def read(self, addr, length=None, burst="incr"):
# 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(
Expand Down

0 comments on commit b9cc5c5

Please sign in to comment.