Skip to content

Commit

Permalink
Add bufsize argument to TCPInterface.recv()
Browse files Browse the repository at this point in the history
Default to 4096, the reasonable example value from upstream docs, which is
commonly used in existing agents.
  • Loading branch information
BrianJKoopman committed Nov 21, 2024
1 parent 74a89e3 commit 97d00a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion socs/agents/cryomech_cpa/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_data(self):
Gets the raw data from the PTC and returns it in a usable format.
"""
self.send(self.buildRegistersQuery())
data = self.recv()
data = self.recv(1024)
data_flag, brd = self.breakdownReplyData(data)

return data_flag, brd
Expand Down
9 changes: 7 additions & 2 deletions socs/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,18 @@ def _check_ready(self):
if not sel.select(self.timeout):
raise ConnectionError("Socket not ready to read. Possible timeout.")

def recv(self):
def recv(self, bufsize=4096):
"""Receive response from the device.
This method will check if the socket is ready to be read from before
performing the recv. If there is no data to read, or the socket is
otherwise unready an exception is raised.
Parameters
----------
bufsize : int
Amount of data to be recieved in bytes. Defaults to 4096.
Returns
-------
``str`` or ``bytes``
Expand All @@ -143,7 +148,7 @@ def recv(self):
"""
self._check_ready()
data = self.comm.recv(1024)
data = self.comm.recv(bufsize)
return data

def __del__(self):
Expand Down

0 comments on commit 97d00a1

Please sign in to comment.