On Fri, Nov 12, 2021 at 02:10:36AM -0300, Leonardo Bras wrote: > Adds io_writev_zerocopy and io_flush_zerocopy as optional callback to > QIOChannelClass, > allowing the implementation of zerocopy writes by subclasses. > > How to use them: > - Write data using qio_channel_writev_zerocopy(), > - Wait write completion with qio_channel_flush_zerocopy(). > > Notes: > As some zerocopy implementations work asynchronously, it's > recommended to keep the write buffer untouched until the return of > qio_channel_flush_zerocopy(), to avoid the risk of sending an updated > buffer instead of the one at the write. > > As the new callbacks are optional, if a subclass does not implement them, > then: > - io_writev_zerocopy will return -1, > - io_flush_zerocopy will return 0 without changing anything. > > Also, some functions like qio_channel_writev_full_all() were adapted to > receive a flag parameter. That allows shared code between zerocopy and > non-zerocopy writev. > > Signed-off-by: Leonardo Bras <leob...@redhat.com> > --- > include/io/channel.h | 93 ++++++++++++++++++++++++++++++++++++++------ > io/channel.c | 65 +++++++++++++++++++++++++------ > 2 files changed, 135 insertions(+), 23 deletions(-) >
> +/** > + * qio_channel_flush_zerocopy: > + * @ioc: the channel object > + * @errp: pointer to a NULL-initialized error object > + * > + * Will block until every packet queued with > + * qio_channel_writev_zerocopy() is sent, or return > + * in case of any error. > + * > + * Returns -1 if any error is found, 0 otherwise. Returns -1 if any error is found, 0 if all data was sent, or 1 if all data was sent but at least some was copied. > + * If not implemented, acts as a no-op, and returns 0. > + */ > + > +int qio_channel_flush_zerocopy(QIOChannel *ioc, > + Error **errp); 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 :|