mirror of https://github.com/xqemu/xqemu.git
iov: reorganize iov_send_recv, part 3
"si" and "ei" are merged in a single variable. Reviewed-by: Juan Quintela <quintela@redhat.com> Reviewed-by: Orit Wassermann <owasserm@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
5209d6753c
commit
f48869ad28
30
util/iov.c
30
util/iov.c
|
@ -146,7 +146,7 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
size_t orig_len, tail;
|
size_t orig_len, tail;
|
||||||
unsigned si, ei; /* start and end indexes */
|
unsigned niov;
|
||||||
|
|
||||||
if (bytes == 0) {
|
if (bytes == 0) {
|
||||||
/* Catch the do-nothing case early, as otherwise we will pass an
|
/* Catch the do-nothing case early, as otherwise we will pass an
|
||||||
|
@ -158,15 +158,15 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
|
||||||
|
|
||||||
/* Find the start position, skipping `offset' bytes:
|
/* Find the start position, skipping `offset' bytes:
|
||||||
* first, skip all full-sized vector elements, */
|
* first, skip all full-sized vector elements, */
|
||||||
for (si = 0; si < iov_cnt && offset >= iov[si].iov_len; ++si) {
|
for (niov = 0; niov < iov_cnt && offset >= iov[niov].iov_len; ++niov) {
|
||||||
offset -= iov[si].iov_len;
|
offset -= iov[niov].iov_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* si == iov_cnt would only be valid if bytes == 0, which
|
/* niov == iov_cnt would only be valid if bytes == 0, which
|
||||||
* we already ruled out above. */
|
* we already ruled out above. */
|
||||||
assert(si < iov_cnt);
|
assert(niov < iov_cnt);
|
||||||
iov += si;
|
iov += niov;
|
||||||
iov_cnt -= si;
|
iov_cnt -= niov;
|
||||||
|
|
||||||
if (offset) {
|
if (offset) {
|
||||||
/* second, skip `offset' bytes from the (now) first element,
|
/* second, skip `offset' bytes from the (now) first element,
|
||||||
|
@ -177,23 +177,23 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
|
||||||
/* Find the end position skipping `bytes' bytes: */
|
/* Find the end position skipping `bytes' bytes: */
|
||||||
/* first, skip all full-sized elements */
|
/* first, skip all full-sized elements */
|
||||||
tail = bytes;
|
tail = bytes;
|
||||||
for (ei = 0; ei < iov_cnt && iov[ei].iov_len <= tail; ++ei) {
|
for (niov = 0; niov < iov_cnt && iov[niov].iov_len <= tail; ++niov) {
|
||||||
tail -= iov[ei].iov_len;
|
tail -= iov[niov].iov_len;
|
||||||
}
|
}
|
||||||
if (tail) {
|
if (tail) {
|
||||||
/* second, fixup the last element, and remember the original
|
/* second, fixup the last element, and remember the original
|
||||||
* length */
|
* length */
|
||||||
assert(ei < iov_cnt);
|
assert(niov < iov_cnt);
|
||||||
assert(iov[ei].iov_len > tail);
|
assert(iov[niov].iov_len > tail);
|
||||||
orig_len = iov[ei].iov_len;
|
orig_len = iov[niov].iov_len;
|
||||||
iov[ei++].iov_len = tail;
|
iov[niov++].iov_len = tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = do_send_recv(sockfd, iov, ei, do_send);
|
ret = do_send_recv(sockfd, iov, niov, do_send);
|
||||||
|
|
||||||
/* Undo the changes above */
|
/* Undo the changes above */
|
||||||
if (tail) {
|
if (tail) {
|
||||||
iov[ei-1].iov_len = orig_len;
|
iov[niov-1].iov_len = orig_len;
|
||||||
}
|
}
|
||||||
if (offset) {
|
if (offset) {
|
||||||
iov[0].iov_base -= offset;
|
iov[0].iov_base -= offset;
|
||||||
|
|
Loading…
Reference in New Issue