diff options
author | Marc-André Lureau | 2022-10-06 13:36:52 +0200 |
---|---|---|
committer | Marc-André Lureau | 2022-10-12 17:22:00 +0200 |
commit | c1f798091319c74cd9a90f36af604c782e7ee7bd (patch) | |
tree | 62b386f2c9ed9f8f9a22e29c190dc26f7d0df773 /util | |
parent | win32: set threads name (diff) | |
download | qemu-c1f798091319c74cd9a90f36af604c782e7ee7bd.tar.gz qemu-c1f798091319c74cd9a90f36af604c782e7ee7bd.tar.xz qemu-c1f798091319c74cd9a90f36af604c782e7ee7bd.zip |
osdep: make readv_writev() work with partial read/write
With a pipe or other reasons, read/write may return less than the
requested bytes. This happens with the test-io-channel-command test on
Windows. glib spawn code uses a binary pipe of 4096 bytes, and the first
read returns that much (although more are requested), for some unclear
reason...
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20221006113657.2656108-2-marcandre.lureau@redhat.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/osdep.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/util/osdep.c b/util/osdep.c index 60fcbbaebe..746d5f7d71 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -538,18 +538,22 @@ int socket_init(void) #ifndef CONFIG_IOVEC -/* helper function for iov_send_recv() */ static ssize_t readv_writev(int fd, const struct iovec *iov, int iov_cnt, bool do_write) { unsigned i = 0; ssize_t ret = 0; + ssize_t off = 0; while (i < iov_cnt) { ssize_t r = do_write - ? write(fd, iov[i].iov_base, iov[i].iov_len) - : read(fd, iov[i].iov_base, iov[i].iov_len); + ? write(fd, iov[i].iov_base + off, iov[i].iov_len - off) + : read(fd, iov[i].iov_base + off, iov[i].iov_len - off); if (r > 0) { ret += r; + off += r; + if (off < iov[i].iov_len) { + continue; + } } else if (!r) { break; } else if (errno == EINTR) { @@ -562,6 +566,7 @@ readv_writev(int fd, const struct iovec *iov, int iov_cnt, bool do_write) } break; } + off = 0; i++; } return ret; |