diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2022-10-06 15:36:53 +0400 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2022-10-12 19:22:01 +0400 |
commit | 3f08376c2e1c3d3bb0b415fb1505b949d72655d4 (patch) | |
tree | 71169eaca96bc299b7cba33e18c7994b756e5b35 | |
parent | c1f798091319c74cd9a90f36af604c782e7ee7bd (diff) | |
download | qemu-3f08376c2e1c3d3bb0b415fb1505b949d72655d4.zip qemu-3f08376c2e1c3d3bb0b415fb1505b949d72655d4.tar.gz qemu-3f08376c2e1c3d3bb0b415fb1505b949d72655d4.tar.bz2 |
util: make do_send_recv work with partial send/recv
According to msdn documentation and Linux man pages, send() should try
to send as much as possible in blocking mode, while recv() may return
earlier with a smaller available amount, we should try to continue
send/recv from there.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20221006113657.2656108-3-marcandre.lureau@redhat.com>
-rw-r--r-- | util/iov.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -111,12 +111,17 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bool do_send) /*XXX Note: windows has WSASend() and WSARecv() */ unsigned i = 0; ssize_t ret = 0; + ssize_t off = 0; while (i < iov_cnt) { ssize_t r = do_send - ? send(sockfd, iov[i].iov_base, iov[i].iov_len, 0) - : recv(sockfd, iov[i].iov_base, iov[i].iov_len, 0); + ? send(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, 0) + : recv(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, 0); if (r > 0) { ret += r; + off += r; + if (off < iov[i].iov_len) { + continue; + } } else if (!r) { break; } else if (errno == EINTR) { @@ -129,6 +134,7 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bool do_send) } break; } + off = 0; i++; } return ret; |