diff options
author | Jiri Pirko <jpirko@redhat.com> | 2012-05-28 12:05:27 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@redhat.com> | 2012-05-29 09:46:01 (GMT) |
commit | d733f8a0a65a817d16ebaa1a8f5ad1330682b489 (patch) | |
tree | ff8f52ba551882b8a600801ba69215dcec9c1b42 /lib/nl.c | |
parent | 970f5d0221863b1473740455ca4d8cefcb34ff31 (diff) | |
download | libnl-d733f8a0a65a817d16ebaa1a8f5ad1330682b489.zip libnl-d733f8a0a65a817d16ebaa1a8f5ad1330682b489.tar.gz libnl-d733f8a0a65a817d16ebaa1a8f5ad1330682b489.tar.bz2 |
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/nl.c')
-rw-r--r-- | lib/nl.c | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -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 */ |