On 10/10/2017 10:43 AM, Daniel P. Berrange wrote: > Currently most outbound I/O on the websock channel gets copied into the > rawoutput buffer, and then immediately copied again into the encoutput > buffer, with a header prepended. Now that qio_channel_websock_encode > accepts a struct iovec, we can trivially remove this bounce buffering > and write directly to encoutput. > > In doing so, we also now correctly validate the encoutput size against > the QIO_CHANNEL_WEBSOCK_MAX_BUFFER limit. > > Signed-off-by: Daniel P. Berrange <[email protected]> > --- > include/io/channel-websock.h | 1 - > io/channel-websock.c | 64 > +++++++++++++++++++------------------------- > 2 files changed, 28 insertions(+), 37 deletions(-) >
> - iov.iov_base = ioc->rawoutput.buffer;
> - iov.iov_len = ioc->rawoutput.offset;
> qio_channel_websock_encode(ioc, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE,
> - &iov, 1, iov.iov_len);
> - buffer_reset(&ioc->rawoutput);
> + iov, niov, size);
If 4/7 changes this to compute size from the iov/niov, then this has
knock-on impact.
> @@ -1115,32 +1118,21 @@ static ssize_t qio_channel_websock_writev(QIOChannel
> *ioc,
> return -1;
> + avail = wioc->encoutput.offset >= QIO_CHANNEL_WEBSOCK_MAX_BUFFER ?
> + 0 : (QIO_CHANNEL_WEBSOCK_MAX_BUFFER - wioc->encoutput.offset);
> + if (want > avail) {
> + want = avail;
> }
>
> - done:
> - if (wioc->rawoutput.offset) {
> - struct iovec iov = { .iov_base = wioc->rawoutput.buffer,
> - .iov_len = wioc->rawoutput.offset };
> + if (want) {
> qio_channel_websock_encode(wioc,
> QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME,
> - &iov, 1, iov.iov_len);
> - buffer_reset(&wioc->rawoutput);
> + iov, niov, want);
then again, I see that you DO support want < iov_size(iov, niov).
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
