From 23845e942cc8fdad05f722b384266cb0a166edc3 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Fri, 25 Mar 2011 18:11:52 +0100 Subject: Add nl_send_sync() Function which sends message using nl_send_auto(), frees the message and waits for ACK/error message (if auto-ack is not disabled). --- include/netlink/netlink.h | 1 + lib/nl.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/netlink/netlink.h b/include/netlink/netlink.h index 099a83e..a13c48f 100644 --- a/include/netlink/netlink.h +++ b/include/netlink/netlink.h @@ -59,6 +59,7 @@ extern void nl_auto_complete(struct nl_sock *, extern int nl_send_auto(struct nl_sock *, struct nl_msg *); extern int nl_send_auto_complete(struct nl_sock *, struct nl_msg *); +extern int nl_send_sync(struct nl_sock *, struct nl_msg *); extern int nl_send_simple(struct nl_sock *, int, int, void *, size_t); diff --git a/lib/nl.c b/lib/nl.c index 8f6f5f1..b70242c 100644 --- a/lib/nl.c +++ b/lib/nl.c @@ -346,6 +346,37 @@ int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg) } /** + * Send netlink message and wait for response (sync request-response) + * @arg sk Netlink socket + * @arg msg Netlink message to be sent + * + * This function takes a netlink message and sends it using nl_send_auto(). + * It will then wait for the response (ACK or error message) to be + * received. Threfore this function will block until the operation has + * been completed. + * + * @note Disabling auto-ack (nl_socket_disable_auto_ack()) will cause + * this function to return immediately after sending. In this case, + * it is the responsibility of the caller to handle any eventual + * error messages returned. + * + * @see nl_send_auto(). + * + * @return 0 on success or a negative error code. + */ +int nl_send_sync(struct nl_sock *sk, struct nl_msg *msg) +{ + int err; + + err = nl_send_auto(sk, msg); + nlmsg_free(msg); + if (err < 0) + return err; + + return wait_for_ack(sk); +} + +/** * Send simple netlink message using nl_send_auto_complete() * @arg sk Netlink socket. * @arg type Netlink message type. -- cgit v0.12