io: add new qio_channel_{readv, writev, read, write}_all functions

These functions wait until they are able to read / write the full
requested data buffer(s).

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2017-08-30 14:53:59 +01:00
parent 50ea44f077
commit d4622e5588
3 changed files with 193 additions and 93 deletions

View file

@ -268,6 +268,58 @@ ssize_t qio_channel_writev_full(QIOChannel *ioc,
size_t nfds,
Error **errp);
/**
* qio_channel_readv_all:
* @ioc: the channel object
* @iov: the array of memory regions to read data into
* @niov: the length of the @iov array
* @errp: pointer to a NULL-initialized error object
*
* Read data from the IO channel, storing it in the
* memory regions referenced by @iov. Each element
* in the @iov will be fully populated with data
* before the next one is used. The @niov parameter
* specifies the total number of elements in @iov.
*
* The function will wait for all requested data
* to be read, yielding from the current coroutine
* if required.
*
* If end-of-file occurs before all requested data
* has been read, an error will be reported.
*
* Returns: 0 if all bytes were read, or -1 on error
*/
int qio_channel_readv_all(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
Error **errp);
/**
* qio_channel_writev_all:
* @ioc: the channel object
* @iov: the array of memory regions to write data from
* @niov: the length of the @iov array
* @errp: pointer to a NULL-initialized error object
*
* Write data to the IO channel, reading it from the
* memory regions referenced by @iov. Each element
* in the @iov will be fully sent, before the next
* one is used. The @niov parameter specifies the
* total number of elements in @iov.
*
* The function will wait for all requested data
* to be written, yielding from the current coroutine
* if required.
*
* Returns: 0 if all bytes were written, or -1 on error
*/
int qio_channel_writev_all(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
Error **erp);
/**
* qio_channel_readv:
* @ioc: the channel object
@ -330,6 +382,44 @@ ssize_t qio_channel_write(QIOChannel *ioc,
size_t buflen,
Error **errp);
/**
* qio_channel_read_all:
* @ioc: the channel object
* @buf: the memory region to read data into
* @buflen: the number of bytes to @buf
* @errp: pointer to a NULL-initialized error object
*
* Reads @buflen bytes into @buf, possibly blocking or (if the
* channel is non-blocking) yielding from the current coroutine
* multiple times until the entire content is read. If end-of-file
* occurs it will return an error rather than a short-read. Otherwise
* behaves as qio_channel_read().
*
* Returns: 0 if all bytes were read, or -1 on error
*/
int qio_channel_read_all(QIOChannel *ioc,
char *buf,
size_t buflen,
Error **errp);
/**
* qio_channel_write_all:
* @ioc: the channel object
* @buf: the memory region to write data into
* @buflen: the number of bytes to @buf
* @errp: pointer to a NULL-initialized error object
*
* Writes @buflen bytes from @buf, possibly blocking or (if the
* channel is non-blocking) yielding from the current coroutine
* multiple times until the entire content is written. Otherwise
* behaves as qio_channel_write().
*
* Returns: 0 if all bytes were written, or -1 on error
*/
int qio_channel_write_all(QIOChannel *ioc,
const char *buf,
size_t buflen,
Error **errp);
/**
* qio_channel_set_blocking:
* @ioc: the channel object