[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 3/7] util: make do_send_recv work with partial send/recv
From: |
marcandre . lureau |
Subject: |
[PULL 3/7] util: make do_send_recv work with partial send/recv |
Date: |
Wed, 12 Oct 2022 20:04:40 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
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>
---
util/iov.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/util/iov.c b/util/iov.c
index 22d6996cce..b4be580022 100644
--- a/util/iov.c
+++ b/util/iov.c
@@ -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;
--
2.37.3
- [PULL 0/7] Win32 patches, marcandre . lureau, 2022/10/12
- [PULL 1/7] win32: set threads name, marcandre . lureau, 2022/10/12
- [PULL 3/7] util: make do_send_recv work with partial send/recv,
marcandre . lureau <=
- [PULL 2/7] osdep: make readv_writev() work with partial read/write, marcandre . lureau, 2022/10/12
- [PULL 6/7] io/command: implement support for win32, marcandre . lureau, 2022/10/12
- [PULL 4/7] tests/channel-helper: set blocking in main thread, marcandre . lureau, 2022/10/12
- [PULL 5/7] io/command: use glib GSpawn, instead of open-coding fork/exec, marcandre . lureau, 2022/10/12
- [PULL 7/7] tests/unit: make test-io-channel-command work on win32, marcandre . lureau, 2022/10/12
- Re: [PULL 0/7] Win32 patches, Stefan Hajnoczi, 2022/10/13