* David Gibson (da...@gibson.dropbear.id.au) wrote: > On Fri, Oct 03, 2014 at 06:47:17PM +0100, Dr. David Alan Gilbert (git) wrote: > > From: "Dr. David Alan Gilbert" <dgilb...@redhat.com> > > > > 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 <dgilb...@redhat.com> > > --- > > qemu-file.c | 39 +++++++++++++++++++++++++++++++++++---- > > 1 file changed, 35 insertions(+), 4 deletions(-) > > > > diff --git a/qemu-file.c b/qemu-file.c > > index 7393415..57eabd8 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. > > Is that safe? This gives the caller no means to detect a partially > completed send.
Well I'm returning the -err, so the caller knows something has gone wrong - it just doesn't know whether it managed to send some part of the data before the failure. Dave > > > + */ > > + 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) > > -- > David Gibson | I'll have my music baroque, and my code > david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ > _other_ > | _way_ _around_! > http://www.ozlabs.org/~dgibson -- Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK