io: Yield rather than wait when already in coroutine
The new qio_channel_{read,write}{,v}_all functions are documented as yielding until data is available. When used on a blocking channel, this yield is done via qio_channel_wait() which spawns a nested event loop under the hood (so it is that secondary loop which yields as needed); but if we are already in a coroutine (at which point QIO_CHANNEL_ERR_BLOCK is only possible if we are a non-blocking channel), we want to yield the current coroutine instead of spawning a nested event loop. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <20170905191114.5959-2-eblake@redhat.com> Acked-by: Daniel P. Berrange <berrange@redhat.com> [commit message updated] Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
3f5c4076f1
commit
9ffb827020
12
io/channel.c
12
io/channel.c
@ -105,7 +105,11 @@ int qio_channel_readv_all(QIOChannel *ioc,
|
|||||||
ssize_t len;
|
ssize_t len;
|
||||||
len = qio_channel_readv(ioc, local_iov, nlocal_iov, errp);
|
len = qio_channel_readv(ioc, local_iov, nlocal_iov, errp);
|
||||||
if (len == QIO_CHANNEL_ERR_BLOCK) {
|
if (len == QIO_CHANNEL_ERR_BLOCK) {
|
||||||
qio_channel_wait(ioc, G_IO_IN);
|
if (qemu_in_coroutine()) {
|
||||||
|
qio_channel_yield(ioc, G_IO_IN);
|
||||||
|
} else {
|
||||||
|
qio_channel_wait(ioc, G_IO_IN);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if (len < 0) {
|
} else if (len < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -143,7 +147,11 @@ int qio_channel_writev_all(QIOChannel *ioc,
|
|||||||
ssize_t len;
|
ssize_t len;
|
||||||
len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp);
|
len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp);
|
||||||
if (len == QIO_CHANNEL_ERR_BLOCK) {
|
if (len == QIO_CHANNEL_ERR_BLOCK) {
|
||||||
qio_channel_wait(ioc, G_IO_OUT);
|
if (qemu_in_coroutine()) {
|
||||||
|
qio_channel_yield(ioc, G_IO_OUT);
|
||||||
|
} else {
|
||||||
|
qio_channel_wait(ioc, G_IO_OUT);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user