qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org
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	[thread overview]
Message-ID: <20171011123143.GH20372@redhat.com> (raw)
In-Reply-To: <731291c2-90f9-e83a-73d7-ebe42da13d0c@redhat.com>

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 <berrange@redhat.com>
> 
> > +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	other threads:[~2017-10-11 12:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-11 10:09 [Qemu-devel] [PATCH v2 0/7] Limit websockets memory usage & other bug fixes Daniel P. Berrange
2017-10-11 10:09 ` [Qemu-devel] [PATCH v2 1/7] io: monitor encoutput buffer size from websocket GSource Daniel P. Berrange
2017-10-11 10:09 ` [Qemu-devel] [PATCH v2 2/7] io: simplify websocket ping reply handling Daniel P. Berrange
2017-10-11 10:09 ` [Qemu-devel] [PATCH v2 3/7] io: get rid of qio_channel_websock_encode helper method Daniel P. Berrange
2017-10-11 10:09 ` [Qemu-devel] [PATCH v2 4/7] io: pass a struct iovec into qio_channel_websock_encode Daniel P. Berrange
2017-10-11 12:28   ` Eric Blake
2017-10-11 12:30   ` Eric Blake
2017-10-11 12:31     ` Daniel P. Berrange [this message]
2017-10-11 10:09 ` [Qemu-devel] [PATCH v2 5/7] io: get rid of bounce buffering in websock write path Daniel P. Berrange
2017-10-11 12:58   ` Eric Blake
2017-10-11 10:09 ` [Qemu-devel] [PATCH v2 6/7] io: cope with websock 'Connection' header having multiple values Daniel P. Berrange
2017-10-11 10:09 ` [Qemu-devel] [PATCH v2 7/7] io: add trace points for websocket HTTP protocol headers Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171011123143.GH20372@redhat.com \
    --to=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).