void qio_channel_wait(QIOChannel *ioc,
GIOCondition condition);
+/**
+ * qio_channel_wait_cond:
+ * @ioc: the channel object
+ * @condition: the I/O condition to wait for
+ *
+ * Block execution from the current thread until
+ * the condition indicated by @condition becomes
+ * available.
+ *
+ * This will work with/without a coroutine context, by automatically select
+ * the proper API to wait.
+ */
+void qio_channel_wait_cond(QIOChannel *ioc,
+ GIOCondition condition);
+
/**
* qio_channel_set_aio_fd_handler:
* @ioc: the channel object
len = qio_channel_readv_full(ioc, local_iov, nlocal_iov, local_fds,
local_nfds, flags, errp);
if (len == QIO_CHANNEL_ERR_BLOCK) {
- if (qemu_in_coroutine()) {
- qio_channel_yield(ioc, G_IO_IN);
- } else {
- qio_channel_wait(ioc, G_IO_IN);
- }
+ qio_channel_wait_cond(ioc, G_IO_IN);
continue;
}
nfds, flags, errp);
if (len == QIO_CHANNEL_ERR_BLOCK) {
- if (qemu_in_coroutine()) {
- qio_channel_yield(ioc, G_IO_OUT);
- } else {
- qio_channel_wait(ioc, G_IO_OUT);
- }
+ qio_channel_wait_cond(ioc, G_IO_OUT);
continue;
}
if (len < 0) {
g_main_context_unref(ctxt);
}
+void qio_channel_wait_cond(QIOChannel *ioc,
+ GIOCondition condition)
+{
+ if (qemu_in_coroutine()) {
+ qio_channel_yield(ioc, condition);
+ } else {
+ qio_channel_wait(ioc, condition);
+ }
+}
static void qio_channel_finalize(Object *obj)
{
QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING,
&local_error);
if (len == QIO_CHANNEL_ERR_BLOCK) {
- if (qemu_in_coroutine()) {
- qio_channel_yield(f->ioc, G_IO_IN);
- } else {
- qio_channel_wait(f->ioc, G_IO_IN);
- }
+ qio_channel_wait_cond(f->ioc, G_IO_IN);
}
} while (len == QIO_CHANNEL_ERR_BLOCK);