util/jsoncomm: add send_and_recv helper
Often, a message is being sent and followed by a call to `recv` to wait for a reply. Create a simple helper `send_and_recv` that does both in one method. Add a simple check for that helper to the tests.
This commit is contained in:
parent
610d1c45d5
commit
70b971b83d
2 changed files with 23 additions and 0 deletions
|
|
@ -393,3 +393,13 @@ class Socket(contextlib.AbstractContextManager):
|
|||
|
||||
n = self._socket.sendmsg([serialized], cmsg, 0)
|
||||
assert n == len(serialized)
|
||||
|
||||
def send_and_recv(self, payload: object, *, fds: Optional[list] = None):
|
||||
"""Send a message and wait for a reply
|
||||
|
||||
This is a convenience helper that combines `send` and `recv`.
|
||||
See the individual methods for details about the parameters.
|
||||
"""
|
||||
|
||||
self.send(payload, fds=fds)
|
||||
return self.recv()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue