qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v4 11/47] Return path: socket_writev_buffer: Blo


From: David Gibson
Subject: Re: [Qemu-devel] [PATCH v4 11/47] Return path: socket_writev_buffer: Block even on non-blocking fd's
Date: Tue, 18 Nov 2014 14:54:09 +1100
User-agent: Mutt/1.5.23 (2014-03-12)

On Mon, Nov 03, 2014 at 06:59:35PM +0000, Dr. David Alan Gilbert wrote:
> * David Gibson (address@hidden) wrote:
> > On Fri, Oct 03, 2014 at 06:47:17PM +0100, Dr. David Alan Gilbert (git) 
> > wrote:
> > > 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 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.

Right.  Which seems like it could be pretty important.

-- 
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

Attachment: pgp_vRNLF5mM8.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]