Commit 7c4a38bf authored by Jakub Kicinski's avatar Jakub Kicinski

tools: ynl: use MSG_DONTWAIT for getting notifications

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: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
Link: https://lore.kernel.org/r/20240227223032.1835527-16-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 73395b43
...@@ -458,16 +458,20 @@ static int ynl_cb_null(const struct nlmsghdr *nlh, struct ynl_parse_arg *yarg) ...@@ -458,16 +458,20 @@ static int ynl_cb_null(const struct nlmsghdr *nlh, struct ynl_parse_arg *yarg)
return YNL_PARSE_CB_ERROR; 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; struct ynl_sock *ys = yarg->ys;
const struct nlmsghdr *nlh; const struct nlmsghdr *nlh;
ssize_t len, rem; ssize_t len, rem;
int ret; int ret;
len = recv(ys->socket, ys->rx_buf, YNL_SOCKET_BUFFER_SIZE, 0); len = recv(ys->socket, ys->rx_buf, YNL_SOCKET_BUFFER_SIZE, flags);
if (len < 0) if (len < 0) {
if (flags & MSG_DONTWAIT && errno == EAGAIN)
return YNL_PARSE_CB_STOP;
return len; return len;
}
ret = YNL_PARSE_CB_STOP; ret = YNL_PARSE_CB_STOP;
for (rem = len; rem > 0; NLMSG_NEXT(nlh, rem)) { 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) ...@@ -509,6 +513,11 @@ static int ynl_sock_read_msgs(struct ynl_parse_arg *yarg, ynl_parse_cb_t cb)
return ret; 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) static int ynl_recv_ack(struct ynl_sock *ys, int ret)
{ {
struct ynl_parse_arg yarg = { .ys = ys, }; struct ynl_parse_arg yarg = { .ys = ys, };
...@@ -797,18 +806,8 @@ int ynl_ntf_check(struct ynl_sock *ys) ...@@ -797,18 +806,8 @@ int ynl_ntf_check(struct ynl_sock *ys)
int err; int err;
do { do {
/* libmnl doesn't let us pass flags to the recv to make err = __ynl_sock_read_msgs(&yarg, ynl_ntf_trampoline,
* it non-blocking so we need to poll() or peek() :| MSG_DONTWAIT);
*/
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);
if (err < 0) if (err < 0)
return err; return err;
} while (err > 0); } while (err > 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment