diff options
author | Wen Congyang | 2015-05-21 03:50:10 +0200 |
---|---|---|
committer | Stefan Hajnoczi | 2015-06-23 17:05:34 +0200 |
commit | 6b64640dd25846c4de42aa433db56e0ff975993a (patch) | |
tree | 1a02774f495f4fa5bdac5957f4fc415b5233cf93 /util | |
parent | raw-posix: Introduce hdev_is_sg() (diff) | |
download | qemu-6b64640dd25846c4de42aa433db56e0ff975993a.tar.gz qemu-6b64640dd25846c4de42aa433db56e0ff975993a.tar.xz qemu-6b64640dd25846c4de42aa433db56e0ff975993a.zip |
iov: don't touch iov in iov_send_recv()
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Message-id: 555D39D2.4000705@cn.fujitsu.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/iov.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/util/iov.c b/util/iov.c index 2fb18e6654..a0d5934e8e 100644 --- a/util/iov.c +++ b/util/iov.c @@ -133,7 +133,7 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bool do_send) #endif } -ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, +ssize_t iov_send_recv(int sockfd, const struct iovec *_iov, unsigned iov_cnt, size_t offset, size_t bytes, bool do_send) { @@ -141,6 +141,16 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, ssize_t ret; size_t orig_len, tail; unsigned niov; + struct iovec *local_iov, *iov; + + if (bytes <= 0) { + return 0; + } + + local_iov = g_new0(struct iovec, iov_cnt); + iov_copy(local_iov, iov_cnt, _iov, iov_cnt, offset, bytes); + offset = 0; + iov = local_iov; while (bytes > 0) { /* Find the start position, skipping `offset' bytes: @@ -187,6 +197,7 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, if (ret < 0) { assert(errno != EINTR); + g_free(local_iov); if (errno == EAGAIN && total > 0) { return total; } @@ -205,6 +216,7 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bytes -= ret; } + g_free(local_iov); return total; } |