summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi
diff options
context:
space:
mode:
authorVratko Polak <vrpolak@cisco.com>2019-05-07 16:16:06 +0200
committerOle Trøan <otroan@employees.org>2019-05-07 19:03:56 +0000
commit875158acd64244eeae431578e3b5a086d5e1f1c2 (patch)
tree56d8c90b74bc66d7bbc423aa3232bbe79ac4cad8 /src/vpp-api/python/vpp_papi
parent2ce28d6014f44a98f5b3387a4709dd56dbc2f8df (diff)
Allow repeated connects on PAPI socket transport
The previous implementation fails with RuntimeError("cannot set daemon status of active thread") when a second connect() follows first disconnect(). Change-Id: I671005923eb020130a57b0b484a3386a05d7be33 Signed-off-by: Vratko Polak <vrpolak@cisco.com>
Diffstat (limited to 'src/vpp-api/python/vpp_papi')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_transport_socket.py11
1 files changed, 10 insertions, 1 deletions
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 63cb6a6e9e7..646bca38983 100644
--- a/src/vpp-api/python/vpp_papi/vpp_transport_socket.py
+++ b/src/vpp-api/python/vpp_papi/vpp_transport_socket.py
@@ -29,7 +29,7 @@ class VppTransport(object):
self.message_table = {}
self.sque = multiprocessing.Queue()
self.q = multiprocessing.Queue()
- self.message_thread = threading.Thread(target=self.msg_thread_func)
+ self.message_thread = None # Will be set on connect().
def msg_thread_func(self):
while True:
@@ -69,6 +69,12 @@ class VppTransport(object):
def connect(self, name, pfx, msg_handler, rx_qlen):
+ if self.message_thread.daemon is not None:
+ raise RuntimeError(
+ "PAPI socket transport connect: You need to disconnect first.")
+ self.message_thread.daemon = threading.Thread(
+ target=self.msg_thread_func)
+
# Create a UDS socket
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.socket.settimeout(self.read_timeout)
@@ -107,6 +113,7 @@ class VppTransport(object):
return 0
def disconnect(self):
+ # TODO: Should we detect if user forgot to connect first?
rv = 0
try: # Might fail, if VPP closes socket before packet makes it out
rv = self.parent.api.sockclnt_delete(index=self.socket_index)
@@ -116,6 +123,8 @@ class VppTransport(object):
self.socket.close()
self.sque.put(True) # Terminate listening thread
self.message_thread.join()
+ # Allow additional connect() calls.
+ self.message_thread = None
return rv
def suspend(self):