From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X3MsG-0002so-6h for qemu-devel@nongnu.org; Sat, 05 Jul 2014 06:07:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X3Ms6-0007gJ-Ij for qemu-devel@nongnu.org; Sat, 05 Jul 2014 06:07:16 -0400 Received: from mail-qg0-x233.google.com ([2607:f8b0:400d:c04::233]:48277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X3Ms6-0007fM-Ee for qemu-devel@nongnu.org; Sat, 05 Jul 2014 06:07:06 -0400 Received: by mail-qg0-f51.google.com with SMTP id z60so2111919qgd.24 for ; Sat, 05 Jul 2014 03:07:06 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <53B7CE46.4070607@redhat.com> Date: Sat, 05 Jul 2014 12:07:02 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1404495717-4239-1-git-send-email-dgilbert@redhat.com> <1404495717-4239-9-git-send-email-dgilbert@redhat.com> In-Reply-To: <1404495717-4239-9-git-send-email-dgilbert@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 08/46] Return path: socket_writev_buffer: Block even on non-blocking fd's List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert (git)" , qemu-devel@nongnu.org Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, lilei@linux.vnet.ibm.com, quintela@redhat.com Il 04/07/2014 19:41, Dr. David Alan Gilbert (git) ha scritto: > From: "Dr. David Alan Gilbert" > > 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 > --- > qemu-file.c | 39 +++++++++++++++++++++++++++++++++++---- > 1 file changed, 35 insertions(+), 4 deletions(-) > > diff --git a/qemu-file.c b/qemu-file.c > index 98a6d2a..9809428 100644 > --- a/qemu-file.c > +++ b/qemu-file.c > @@ -70,12 +70,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) > I guess the table I just asked about would help clarifying this as well. Also note that g_poll doesn't work on sockets on Windows, but I hope we can avoid it altogether. :) Paolo