From 164c9a762d2ab96ec939bfd6e11c2d4af6f651d6 Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Mon, 23 Oct 2017 19:24:08 +0800 Subject: [PATCH] msg/async: batch handle msg_iovlen. Also remove redundan code "msg.msg_iovlen = 0". Signed-off-by: Jianpeng Ma --- src/msg/async/PosixStack.cc | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/msg/async/PosixStack.cc b/src/msg/async/PosixStack.cc index e0104fdc4bc..2e432b86919 100644 --- a/src/msg/async/PosixStack.cc +++ b/src/msg/async/PosixStack.cc @@ -119,18 +119,15 @@ class PosixConnectedSocketImpl final : public ConnectedSocketImpl { uint64_t size = MIN(left_pbrs, IOV_MAX); left_pbrs -= size; memset(&msg, 0, sizeof(msg)); - msg.msg_iovlen = 0; + msg.msg_iovlen = size; msg.msg_iov = msgvec; unsigned msglen = 0; - while (size > 0) { - msgvec[msg.msg_iovlen].iov_base = (void*)(pb->c_str()); - msgvec[msg.msg_iovlen].iov_len = pb->length(); - msg.msg_iovlen++; - msglen += pb->length(); - ++pb; - size--; + for (auto iov = msgvec; iov != msgvec + size; iov++) { + iov->iov_base = (void*)(pb->c_str()); + iov->iov_len = pb->length(); + msglen += pb->length(); + ++pb; } - ssize_t r = do_sendmsg(_fd, msg, msglen, left_pbrs || more); if (r < 0) return r;