]> granicus.if.org Git - libnl/commitdiff
nl: Make nl_recvmsgs() return the number of netlink messages processed
authorThomas Graf <tgraf@redhat.com>
Sat, 21 Apr 2012 10:46:01 +0000 (12:46 +0200)
committerThomas Graf <tgraf@redhat.com>
Sat, 21 Apr 2012 10:46:01 +0000 (12:46 +0200)
lib/nl.c

index bcf89da78d052ff93a41b1208e1648b0ae4c6705..c41a3b98dd6c1667ca863e5c72ff713c2e9ffe3c 100644 (file)
--- a/lib/nl.c
+++ b/lib/nl.c
@@ -559,7 +559,7 @@ do { \
 
 static int recvmsgs(struct nl_sock *sk, struct nl_cb *cb)
 {
-       int n, err = 0, multipart = 0, interrupted = 0;
+       int n, err = 0, multipart = 0, interrupted = 0, nrecv = 0;
        unsigned char *buf = NULL;
        struct nlmsghdr *hdr;
        struct sockaddr_nl nla = {0};
@@ -594,6 +594,8 @@ continue_reading:
                if (creds)
                        nlmsg_set_creds(msg, creds);
 
+               nrecv++;
+
                /* Raw callback is the first, it gives the most control
                 * to the user and he can do his very own parsing. */
                if (cb->cb_set[NL_CB_MSG_IN])
@@ -754,6 +756,9 @@ out:
        if (interrupted)
                err = -NLE_DUMP_INTR;
 
+       if (!err)
+               err = nrecv;
+
        return err;
 }
 
@@ -770,7 +775,7 @@ out:
  * A non-blocking sockets causes the function to return immediately if
  * no data is available.
  *
- * @return 0 on success or a negative error code from nl_recv().
+ * @return Number of received messages or a negative error code from nl_recv().
  */
 int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb)
 {