summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJiri Pirko <jpirko@redhat.com>2012-05-28 14:05:27 +0200
committerThomas Graf <tgraf@redhat.com>2012-05-29 11:46:01 +0200
commitd733f8a0a65a817d16ebaa1a8f5ad1330682b489 (patch)
treeff8f52ba551882b8a600801ba69215dcec9c1b42 /lib
parent970f5d0221863b1473740455ca4d8cefcb34ff31 (diff)
downloadlibnl-d733f8a0a65a817d16ebaa1a8f5ad1330682b489.tar.gz
use MSG_TRUNC flag to get recv message size at once
prevent multiple calls of recvmsg. Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/nl.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/nl.c b/lib/nl.c
index 64e1382..b572a1a 100644
--- a/lib/nl.c
+++ b/lib/nl.c
@@ -435,7 +435,7 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla,
memset(nla, 0, sizeof(*nla));
if (sk->s_flags & NL_MSG_PEEK)
- flags |= MSG_PEEK;
+ flags |= MSG_PEEK | MSG_TRUNC;
if (page_size == 0)
page_size = getpagesize();
@@ -466,16 +466,17 @@ retry:
}
}
- if (iov.iov_len < n ||
- msg.msg_flags & MSG_TRUNC) {
+ if (msg.msg_flags & MSG_CTRUNC) {
+ msg.msg_controllen *= 2;
+ msg.msg_control = realloc(msg.msg_control, msg.msg_controllen);
+ goto retry;
+ } else if (iov.iov_len < n || msg.msg_flags & MSG_TRUNC) {
/* Provided buffer is not long enough, enlarge it
+ * to size of n (which should be total length of the message)
* and try again. */
- iov.iov_len *= 2;
+ iov.iov_len = n;
iov.iov_base = *buf = realloc(*buf, iov.iov_len);
- goto retry;
- } else if (msg.msg_flags & MSG_CTRUNC) {
- msg.msg_controllen *= 2;
- msg.msg_control = realloc(msg.msg_control, msg.msg_controllen);
+ flags = 0;
goto retry;
} else if (flags != 0) {
/* Buffer is big enough, do the actual reading */