[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 10/47] Return path: socket_writev_buffer: Block e
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v3 10/47] Return path: socket_writev_buffer: Block even on non-blocking fd's |
Date: |
Thu, 28 Aug 2014 16:03:27 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
The return path uses a non-blocking fd so as not to block waiting
for the (possibly broken) destination to finish returning a message,
however we still want outbound data to behave in the same way and block.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
qemu-file.c | 39 +++++++++++++++++++++++++++++++++++----
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/qemu-file.c b/qemu-file.c
index 694e887..2ba59a5 100644
--- a/qemu-file.c
+++ b/qemu-file.c
@@ -85,12 +85,43 @@ static ssize_t socket_writev_buffer(void *opaque, struct
iovec *iov, int iovcnt,
QEMUFileSocket *s = opaque;
ssize_t len;
ssize_t size = iov_size(iov, iovcnt);
+ ssize_t offset = 0;
+ int err;
- len = iov_send(s->fd, iov, iovcnt, 0, size);
- if (len < size) {
- len = -socket_error();
+ while (size > 0) {
+ len = iov_send(s->fd, iov, iovcnt, offset, size);
+
+ if (len > 0) {
+ size -= len;
+ offset += len;
+ }
+
+ if (size > 0) {
+ err = socket_error();
+
+ if (err != EAGAIN) {
+ error_report("socket_writev_buffer: Got err=%d for (%zd/%zd)",
+ err, size, len);
+ /*
+ * If I've already sent some but only just got the error, I
+ * could return the amount validly sent so far and wait for the
+ * next call to report the error, but I'd rather flag the error
+ * immediately.
+ */
+ return -err;
+ }
+
+ /* Emulate blocking */
+ GPollFD pfd;
+
+ pfd.fd = s->fd;
+ pfd.events = G_IO_OUT | G_IO_ERR;
+ pfd.revents = 0;
+ g_poll(&pfd, 1 /* 1 fd */, -1 /* no timeout */);
+ }
}
- return len;
+
+ return offset;
}
static int socket_get_fd(void *opaque)
--
1.9.3
- [Qemu-devel] [PATCH v3 00/47] Postcopy implementation, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 01/47] QEMUSizedBuffer/QEMUFile, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 07/47] Create MigrationIncomingState, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 04/47] qemu_ram_foreach_block: pass up error value, and down the ramblock name, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 03/47] Start documenting how postcopy works., Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 02/47] Tests: QEMUSizedBuffer/QEMUBuffer, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 05/47] improve DPRINTF macros, add to savevm, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 08/47] socket shutdown, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 10/47] Return path: socket_writev_buffer: Block even on non-blocking fd's,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v3 14/47] Return path: Source handling of return path, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 09/47] Return path: Open a return path on QEMUFile for sockets, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 12/47] Return path: Control commands, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 13/47] Return path: Send responses from destination to source, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 16/47] ram_debug_dump_bitmap: Dump a migration bitmap as text, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 17/47] Rework loadvm path for subloops, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 06/47] Add qemu_get_counted_string to read a string prefixed by a count byte, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 18/47] Add migration-capability boolean for postcopy-ram., Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 20/47] QEMU_VM_CMD_PACKAGED: Send a packaged chunk of migration stream, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 22/47] Allow savevm handlers to state whether they could go into postcopy, Dr. David Alan Gilbert (git), 2014/08/28