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:
@@ -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);
|
g_assert(!nle);
|
||||||
|
|
||||||
_LOGD("genl: generic netlink socket for sync operations created: port=%u, fd=%d",
|
_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);
|
g_assert(!nle);
|
||||||
|
|
||||||
nle = nl_socket_set_passcred(priv->sk_rtnl, 1);
|
nle = nl_socket_set_passcred(priv->sk_rtnl, 1);
|
||||||
g_assert(!nle);
|
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);
|
nle = nl_socket_set_buffer_size(priv->sk_rtnl, 8 * 1024 * 1024, 0);
|
||||||
g_assert(!nle);
|
g_assert(!nle);
|
||||||
|
|
||||||
|
@@ -1051,7 +1051,7 @@ nl_socket_disable_msg_peek(struct nl_sock *sk)
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
int
|
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_nlsock struct nl_sock *sk = NULL;
|
||||||
nm_auto_close int fd = -1;
|
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);
|
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)
|
if (fd < 0)
|
||||||
return -nm_errno_from_native(errno);
|
return -nm_errno_from_native(errno);
|
||||||
|
|
||||||
|
@@ -489,7 +489,7 @@ nlmsg_put(struct nl_msg *n, uint32_t pid, uint32_t seq, int type, int payload, i
|
|||||||
|
|
||||||
struct nl_sock;
|
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);
|
void nl_socket_free(struct nl_sock *sk);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user