aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVratko Polak <vrpolak@cisco.com>2019-09-10 13:35:11 +0200
committerDave Barach <openvpp@barachs.net>2020-02-18 13:28:43 +0000
commit1c45b85dff2a0e8c60541cfa5371090fb9502e18 (patch)
tree82549539939e49c2dff2271c95626f29b0877262
parent72ab26ca8f1f4d28c41b39f994ac82f60552f41a (diff)
papi: introduce read_blocking
Previously, self.transport.q got the messages (at least for socket transport), stored in the encoded (packed) form. In order to avoid accessing internals for async reads, a new method is introduced, to perform blocking reads of decoded (unpacked) messages. The method is also used in _call_vpp(), so sync and async reads are kept compatible. Type: feature Change-Id: Id49792dfa57c00b1a14a198031c5398d09a9ba20 Signed-off-by: Vratko Polak <vrpolak@cisco.com> (cherry picked from commit 0938547eaaf5440de28877fa4f873c21bcb8cfbf)
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_papi.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py
index f09f6e013c3..f368bd798df 100644
--- a/src/vpp-api/python/vpp_papi/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi/vpp_papi.py
@@ -645,10 +645,9 @@ class VPPApiClient(object):
# Block until we get a reply.
rl = []
while (True):
- msg = self.transport.read()
- if not msg:
+ r = self.read_blocking(no_type_conversion)
+ if r is None:
raise VPPIOError(2, 'VPP API client: read failed')
- r = self.decode_incoming_msg(msg, no_type_conversion)
msgname = type(r).__name__
if context not in r or r.context == 0 or context != r.context:
# Message being queued
@@ -700,6 +699,33 @@ class VPPApiClient(object):
self.transport.write(b)
return context
+ def read_blocking(self, no_type_conversion=False):
+ """Get next received message from transport within timeout, decoded.
+
+ Note that noticifations have context zero
+ and are not put into receive queue (at least for socket transport),
+ use async_thread with registered callback for processing them.
+
+ If no message appears in the queue within timeout, return None.
+
+ Optionally, type conversion can be skipped,
+ as some of conversions are into less precise types.
+
+ When r is the return value of this, the caller can get message name as:
+ msgname = type(r).__name__
+ and context number (type long) as:
+ context = r.context
+
+ :param no_type_conversion: If false, type conversions are applied.
+ :type no_type_conversion: bool
+ :returns: Decoded message, or None if no message (within timeout).
+ :rtype: Whatever VPPType.unpack returns, depends on no_type_conversion.
+ """
+ msg = self.transport.read()
+ if not msg:
+ return None
+ return self.decode_incoming_msg(msg, no_type_conversion)
+
def register_event_callback(self, callback):
"""Register a callback for async messages.