platform/netlink: add "blocking" argument to nl_socket_new()

Whether we use a socket blockingly or non-blocking is usually determined
upfront and does not change. Make it a parameter of nl_socket_new().
Also, it saves an additional syscall.
This commit is contained in:
Thomas Haller
2022-06-21 20:45:20 +02:00
parent 6b0f67b736
commit 260d693ec4
3 changed files with 5 additions and 8 deletions

View File

@@ -9747,7 +9747,7 @@ constructed(GObject *_object)
/*************************************************************************/
nle = nl_socket_new(&priv->sk_genl_sync, NETLINK_GENERIC);
nle = nl_socket_new(&priv->sk_genl_sync, NETLINK_GENERIC, TRUE);
g_assert(!nle);
_LOGD("genl: generic netlink socket for sync operations created: port=%u, fd=%d",
@@ -9756,15 +9756,12 @@ constructed(GObject *_object)
/*************************************************************************/
nle = nl_socket_new(&priv->sk_rtnl, NETLINK_ROUTE);
nle = nl_socket_new(&priv->sk_rtnl, NETLINK_ROUTE, FALSE);
g_assert(!nle);
nle = nl_socket_set_passcred(priv->sk_rtnl, 1);
g_assert(!nle);
nle = nl_socket_set_nonblocking(priv->sk_rtnl);
g_assert(!nle);
nle = nl_socket_set_buffer_size(priv->sk_rtnl, 8 * 1024 * 1024, 0);
g_assert(!nle);

View File

@@ -1051,7 +1051,7 @@ nl_socket_disable_msg_peek(struct nl_sock *sk)
/*****************************************************************************/
int
nl_socket_new(struct nl_sock **out_sk, int protocol)
nl_socket_new(struct nl_sock **out_sk, int protocol, bool blocking)
{
nm_auto_nlsock struct nl_sock *sk = NULL;
nm_auto_close int fd = -1;
@@ -1063,7 +1063,7 @@ nl_socket_new(struct nl_sock **out_sk, int protocol)
nm_assert(out_sk && !*out_sk);
fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, protocol);
fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC | (blocking ? 0 : SOCK_NONBLOCK), protocol);
if (fd < 0)
return -nm_errno_from_native(errno);

View File

@@ -489,7 +489,7 @@ nlmsg_put(struct nl_msg *n, uint32_t pid, uint32_t seq, int type, int payload, i
struct nl_sock;
int nl_socket_new(struct nl_sock **out_sk, int protocol);
int nl_socket_new(struct nl_sock **out_sk, int protocol, bool blocking);
void nl_socket_free(struct nl_sock *sk);