Skip to content

Commit

Permalink
iov: don't touch iov in iov_send_recv()
Browse files Browse the repository at this point in the history
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Message-id: 555D39D2.4000705@cn.fujitsu.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
wencongyang authored and stefanhaRH committed Jun 23, 2015
1 parent 3307ed7 commit 6b64640
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/qemu/iov.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt,
* For iov_send_recv() _whole_ area being sent or received
* should be within the iovec, not only beginning of it.
*/
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);
#define iov_recv(sockfd, iov, iov_cnt, offset, bytes) \
iov_send_recv(sockfd, iov, iov_cnt, offset, bytes, false)
Expand Down
14 changes: 13 additions & 1 deletion util/iov.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,24 @@ 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)
{
ssize_t total = 0;
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:
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 6b64640

Please sign in to comment.