diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2013-03-27 17:36:28 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2013-04-17 11:43:44 +0200 |
commit | cb6247a7e3e07ead908d2e7fbc8848cc2e135056 (patch) | |
tree | 33223836d546d9c764c5c1d1e9dc20fe13f9d2c2 /util | |
parent | 15711565f66de53c22c3a9faee04fc2092409ce4 (diff) | |
download | hqemu-cb6247a7e3e07ead908d2e7fbc8848cc2e135056.zip hqemu-cb6247a7e3e07ead908d2e7fbc8848cc2e135056.tar.gz |
iov: reorganize iov_send_recv, part 1
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.
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Orit Wassermann <owasserm@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/iov.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -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; |