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 <berra...@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 :|