netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	nicolas.dichtel@6wind.com, donald.hunter@gmail.com,
	jiri@resnulli.us, sdf@google.com,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 15/15] tools: ynl: use MSG_DONTWAIT for getting notifications
Date: Mon, 26 Feb 2024 13:20:21 -0800	[thread overview]
Message-ID: <20240226212021.1247379-16-kuba@kernel.org> (raw)
In-Reply-To: <20240226212021.1247379-1-kuba@kernel.org>

To stick to libmnl wrappers in the past we had to use poll()
to check if there are any outstanding notifications on the socket.
This is no longer necessary, we can use MSG_DONTWAIT.

Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/net/ynl/lib/ynl.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/tools/net/ynl/lib/ynl.c b/tools/net/ynl/lib/ynl.c
index f8a66ae88ba9..86729119e1ef 100644
--- a/tools/net/ynl/lib/ynl.c
+++ b/tools/net/ynl/lib/ynl.c
@@ -458,16 +458,20 @@ static int ynl_cb_null(const struct nlmsghdr *nlh, struct ynl_parse_arg *yarg)
 	return YNL_PARSE_CB_ERROR;
 }
 
-static int ynl_sock_read_msgs(struct ynl_parse_arg *yarg, ynl_parse_cb_t cb)
+static int
+__ynl_sock_read_msgs(struct ynl_parse_arg *yarg, ynl_parse_cb_t cb, int flags)
 {
 	struct ynl_sock *ys = yarg->ys;
 	const struct nlmsghdr *nlh;
 	ssize_t len, rem;
 	int ret;
 
-	len = recv(ys->socket, ys->rx_buf, YNL_SOCKET_BUFFER_SIZE, 0);
-	if (len < 0)
+	len = recv(ys->socket, ys->rx_buf, YNL_SOCKET_BUFFER_SIZE, flags);
+	if (len < 0) {
+		if (flags & MSG_DONTWAIT && errno == EAGAIN)
+			return YNL_PARSE_CB_STOP;
 		return len;
+	}
 
 	ret = YNL_PARSE_CB_STOP;
 	for (rem = len; rem > 0; NLMSG_NEXT(nlh, rem)) {
@@ -509,6 +513,11 @@ static int ynl_sock_read_msgs(struct ynl_parse_arg *yarg, ynl_parse_cb_t cb)
 	return ret;
 }
 
+static int ynl_sock_read_msgs(struct ynl_parse_arg *yarg, ynl_parse_cb_t cb)
+{
+	return __ynl_sock_read_msgs(yarg, cb, 0);
+}
+
 static int ynl_recv_ack(struct ynl_sock *ys, int ret)
 {
 	struct ynl_parse_arg yarg = { .ys = ys, };
@@ -797,18 +806,8 @@ int ynl_ntf_check(struct ynl_sock *ys)
 	int err;
 
 	do {
-		/* libmnl doesn't let us pass flags to the recv to make
-		 * it non-blocking so we need to poll() or peek() :|
-		 */
-		struct pollfd pfd = { };
-
-		pfd.fd = ys->socket;
-		pfd.events = POLLIN;
-		err = poll(&pfd, 1, 1);
-		if (err < 1)
-			return err;
-
-		err = ynl_sock_read_msgs(&yarg, ynl_ntf_trampoline);
+		err = __ynl_sock_read_msgs(&yarg, ynl_ntf_trampoline,
+					   MSG_DONTWAIT);
 		if (err < 0)
 			return err;
 	} while (err > 0);
-- 
2.43.2


      parent reply	other threads:[~2024-02-26 21:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26 21:20 [PATCH net-next v2 00/15] tools: ynl: stop using libmnl Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 01/15] tools: ynl: give up on libmnl for auto-ints Jakub Kicinski
2024-02-27 10:38   ` Nicolas Dichtel
2024-02-26 21:20 ` [PATCH net-next v2 02/15] tools: ynl: create local attribute helpers Jakub Kicinski
2024-02-27 11:05   ` Nicolas Dichtel
2024-02-27 14:56     ` Jakub Kicinski
2024-02-27 15:10       ` Nicolas Dichtel
2024-02-26 21:20 ` [PATCH net-next v2 03/15] tools: ynl: create local for_each helpers Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 04/15] tools: ynl: create local nlmsg access helpers Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 05/15] tools: ynl: create local ARRAY_SIZE() helper Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 06/15] tools: ynl: make yarg the first member of struct ynl_dump_state Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 07/15] tools: ynl-gen: remove unused parse code Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 08/15] tools: ynl: wrap recv() + mnl_cb_run2() into a single helper Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 09/15] tools: ynl: use ynl_sock_read_msgs() for ACK handling Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 10/15] tools: ynl: stop using mnl_cb_run2() Jakub Kicinski
2024-02-27 11:06   ` Nicolas Dichtel
2024-02-26 21:20 ` [PATCH net-next v2 11/15] tools: ynl: switch away from mnl_cb_t Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 12/15] tools: ynl: switch away from MNL_CB_* Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 13/15] tools: ynl: stop using mnl socket helpers Jakub Kicinski
2024-02-26 21:20 ` [PATCH net-next v2 14/15] tools: ynl: remove the libmnl dependency Jakub Kicinski
2024-02-26 21:20 ` Jakub Kicinski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240226212021.1247379-16-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.dichtel@6wind.com \
    --cc=pabeni@redhat.com \
    --cc=sdf@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).