From f22824bbefdf82168717537090a5471166e20f0d Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Tue, 6 Dec 2022 17:30:49 +0100 Subject: papi: fix async support for socket transport Async use of the API is much faster than blocking calls. Seemed like it only worked over shared memory transport. This patches re-enables support for async calls over socket transport. Type: fix Signed-off-by: Ole Troan Change-Id: I05f3b362035ce0a1c16788ba9003a35601ddb04e Signed-off-by: Ole Troan --- src/vpp-api/python/vpp_papi/vpp_papi.py | 2 +- src/vpp-api/python/vpp_papi/vpp_transport_socket.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/vpp-api/python') diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py index 1e5d23e59b7..6755e227ed1 100644 --- a/src/vpp-api/python/vpp_papi/vpp_papi.py +++ b/src/vpp-api/python/vpp_papi/vpp_papi.py @@ -546,7 +546,7 @@ class VPPApiClient: def connect_internal(self, name, msg_handler, chroot_prefix, rx_qlen, do_async): pfx = chroot_prefix.encode("utf-8") if chroot_prefix else None - rv = self.transport.connect(name, pfx, msg_handler, rx_qlen) + rv = self.transport.connect(name, pfx, msg_handler, rx_qlen, do_async) if rv != 0: raise VPPIOError(2, "Connect failed") self.vpp_dictionary_maxid = self.transport.msg_table_max_index() diff --git a/src/vpp-api/python/vpp_papi/vpp_transport_socket.py b/src/vpp-api/python/vpp_papi/vpp_transport_socket.py index 3a8c332a00a..174ab74d0b8 100644 --- a/src/vpp-api/python/vpp_papi/vpp_transport_socket.py +++ b/src/vpp-api/python/vpp_papi/vpp_transport_socket.py @@ -42,7 +42,7 @@ class VppTransport: while True: try: rlist, _, _ = select.select([self.socket, self.sque._reader], [], []) - except socket.error: + except (socket.error, ValueError): # Terminate thread logging.error("select failed") self.q.put(None) @@ -65,14 +65,14 @@ class VppTransport: return # Put either to local queue or if context == 0 # callback queue - if self.parent.has_context(msg): + if not self.do_async and self.parent.has_context(msg): self.q.put(msg) else: self.parent.msg_handler_async(msg) else: raise VppTransportSocketIOError(2, "Unknown response from select") - def connect(self, name, pfx, msg_handler, rx_qlen): + def connect(self, name, pfx, msg_handler, rx_qlen, do_async=False): # TODO: Reorder the actions and add "roll-backs", # to restore clean disconnect state when failure happens durng connect. @@ -125,6 +125,7 @@ class VppTransport: self.message_table[n] = m.index self.message_thread.daemon = True + self.do_async = do_async self.message_thread.start() return 0 -- cgit 1.2.3-korg