qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2 4/7] io: pass a struct iovec into qio_channel


From: Daniel P. Berrange
Subject: Re: [Qemu-devel] [PATCH v2 4/7] io: pass a struct iovec into qio_channel_websock_encode
Date: Wed, 11 Oct 2017 13:31:43 +0100
User-agent: Mutt/1.9.0 (2017-09-02)

On Wed, Oct 11, 2017 at 07:30:45AM -0500, Eric Blake wrote:
> On 10/11/2017 05:09 AM, Daniel P. Berrange wrote:
> > Instead of requiring use of another Buffer, pass a struct iovec
> > into qio_channel_websock_encode, which gives callers more
> > flexibility in how they process data.
> > 
> > Signed-off-by: Daniel P. Berrange <address@hidden>
> 
> > +static void qio_channel_websock_encode(QIOChannelWebsock *ioc,
> > +                                       uint8_t opcode,
> > +                                       const struct iovec *iov,
> > +                                       size_t niov,
> > +                                       size_t size)
> >  {
> >      size_t header_size;
> > +    size_t i;
> >      union {
> >          char buf[QIO_CHANNEL_WEBSOCK_HEADER_LEN_64_BIT];
> >          QIOChannelWebsockHeader ws;
> 
> Is it worth adding assert(size <= iov_size(iov, niov)) near the top,
> 
> > +    trace_qio_channel_websock_encode(ioc, opcode, header_size, size);
> > +    buffer_reserve(&ioc->encoutput, header_size + size);
> > +    buffer_append(&ioc->encoutput, header.buf, header_size);
> > +    for (i = 0; i < niov && size != 0; i++) {
> > +        size_t want = iov[i].iov_len;
> > +        if (want > size) {
> > +            want = size;
> > +        }
> > +        buffer_append(&ioc->encoutput, iov[i].iov_base, want);
> > +        size -= want;
> > +    }
> 
> so we don't have to worry about a huge size causing us to buffer_reserve
> far too much space?

Sure, I can add that.


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



reply via email to

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