From 527498a6f0ab887fdc9058e73e68f1395a80b58a Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Mon, 14 Oct 2024 17:48:32 -0400 Subject: [PATCH] Add bufsize argument to TCPInterface.recv() Default to 4096, the reasonable example value from upstream docs, which is commonly used in existing agents. --- socs/agents/cryomech_cpa/drivers.py | 2 +- socs/tcp.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/socs/agents/cryomech_cpa/drivers.py b/socs/agents/cryomech_cpa/drivers.py index 179ee319e..8851011f5 100644 --- a/socs/agents/cryomech_cpa/drivers.py +++ b/socs/agents/cryomech_cpa/drivers.py @@ -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 diff --git a/socs/tcp.py b/socs/tcp.py index da5ac8e5a..3b6746d6a 100644 --- a/socs/tcp.py +++ b/socs/tcp.py @@ -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`` @@ -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):