[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241107133004.7469-8-shaw.leon@gmail.com>
Date: Thu, 7 Nov 2024 21:30:02 +0800
From: Xiao Liang <shaw.leon@...il.com>
To: netdev@...r.kernel.org,
linux-kselftest@...r.kernel.org,
Kuniyuki Iwashima <kuniyu@...zon.com>,
Jakub Kicinski <kuba@...nel.org>
Cc: "David S. Miller" <davem@...emloft.net>,
David Ahern <dsahern@...nel.org>,
Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>,
Ido Schimmel <idosch@...dia.com>,
Andrew Lunn <andrew+netdev@...n.ch>,
Simon Horman <horms@...nel.org>,
Donald Hunter <donald.hunter@...il.com>,
Shuah Khan <shuah@...nel.org>,
Jiri Pirko <jiri@...nulli.us>,
Hangbin Liu <liuhangbin@...il.com>
Subject: [PATCH net-next v2 7/8] tools/net/ynl: Add retry limit for async notification
Since commit 1bf70e6c3a53 ("tools/net/ynl: improve async notification
handling"), check_ntf() would block indefinitely if there's no messages.
In some cases we want to set a limit on waiting time. This patch adds
max_reties parameter check_ntf(), and makes it stop when no message is
recievied in that number of consecutive retries.
Signed-off-by: Xiao Liang <shaw.leon@...il.com>
---
tools/net/ynl/lib/ynl.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 92f85698c50e..dff5166a4650 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -907,7 +907,8 @@ class YnlFamily(SpecFamily):
msg['msg'] = attrs
self.async_msg_queue.put(msg)
- def check_ntf(self, interval=0.1):
+ def check_ntf(self, interval=0.1, max_retries=None):
+ retry = 0
while True:
try:
reply = self.sock.recv(self._recv_size, socket.MSG_DONTWAIT)
@@ -933,7 +934,11 @@ class YnlFamily(SpecFamily):
try:
yield self.async_msg_queue.get_nowait()
+ retry = 0
except queue.Empty:
+ retry += 1
+ if max_retries is not None and retry > max_retries:
+ return
try:
time.sleep(interval)
except KeyboardInterrupt:
--
2.47.0
Powered by blists - more mailing lists