From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:45622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKtLD-0006Io-81 for qemu-devel@nongnu.org; Wed, 27 Mar 2013 12:36:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKtL8-0002qg-AL for qemu-devel@nongnu.org; Wed, 27 Mar 2013 12:36:47 -0400 Received: from mail-ee0-f43.google.com ([74.125.83.43]:57926) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKtL8-0002qK-4O for qemu-devel@nongnu.org; Wed, 27 Mar 2013 12:36:42 -0400 Received: by mail-ee0-f43.google.com with SMTP id e50so474466eek.30 for ; Wed, 27 Mar 2013 09:36:41 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 27 Mar 2013 17:36:28 +0100 Message-Id: <1364402192-18169-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1364402192-18169-1-git-send-email-pbonzini@redhat.com> References: <1364402192-18169-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 2/6] iov: reorganize iov_send_recv, part 1 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: owasserm@redhat.com, quintela@redhat.com Once the initial part of the iov is dropped, it is not used anymore. Modify iov/iovcnt directly instead of adjusting them with the "si" variable. Signed-off-by: Paolo Bonzini --- util/iov.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/util/iov.c b/util/iov.c index 9dae318..adb9a70 100644 --- a/util/iov.c +++ b/util/iov.c @@ -159,16 +159,22 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, for (si = 0; si < iov_cnt && offset >= iov[si].iov_len; ++si) { offset -= iov[si].iov_len; } + + /* si == iov_cnt would only be valid if bytes == 0, which + * we already ruled out above. */ + assert(si < iov_cnt); + iov += si; + iov_cnt -= si; + if (offset) { - assert(si < iov_cnt); /* second, skip `offset' bytes from the (now) first element, * undo it on exit */ - iov[si].iov_base += offset; - iov[si].iov_len -= offset; + iov[0].iov_base += offset; + iov[0].iov_len -= offset; } /* Find the end position skipping `bytes' bytes: */ /* first, skip all full-sized elements */ - for (ei = si; ei < iov_cnt && iov[ei].iov_len <= bytes; ++ei) { + for (ei = 0; ei < iov_cnt && iov[ei].iov_len <= bytes; ++ei) { bytes -= iov[ei].iov_len; } if (bytes) { @@ -183,12 +189,12 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, ++ei; } - ret = do_send_recv(sockfd, iov + si, ei - si, do_send); + ret = do_send_recv(sockfd, iov, ei, do_send); /* Undo the changes above */ if (offset) { - iov[si].iov_base -= offset; - iov[si].iov_len += offset; + iov[0].iov_base -= offset; + iov[0].iov_len += offset; } if (bytes) { iov[ei-1].iov_len += bytes; -- 1.8.1.4