X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qemu-coroutine-io.c;h=054ca70627e386198314deb616cfbf47b144619e;hb=60aad298cb6de52f2716b2e82e1353ea9de95fd6;hp=5fae9c7d47207555b4831e8a884d787d1373602a;hpb=737e150e89c44c6b33691a627e24bac7fb58f349;p=qemu.git diff --git a/qemu-coroutine-io.c b/qemu-coroutine-io.c index 5fae9c7d4..054ca7062 100644 --- a/qemu-coroutine-io.c +++ b/qemu-coroutine-io.c @@ -23,9 +23,10 @@ * THE SOFTWARE. */ #include "qemu-common.h" -#include "qemu_socket.h" +#include "qemu/sockets.h" #include "block/coroutine.h" -#include "iov.h" +#include "qemu/iov.h" +#include "qemu/main-loop.h" ssize_t coroutine_fn qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt, @@ -63,3 +64,26 @@ qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send) struct iovec iov = { .iov_base = buf, .iov_len = bytes }; return qemu_co_sendv_recvv(sockfd, &iov, 1, 0, bytes, do_send); } + +typedef struct { + Coroutine *co; + int fd; +} FDYieldUntilData; + +static void fd_coroutine_enter(void *opaque) +{ + FDYieldUntilData *data = opaque; + qemu_set_fd_handler(data->fd, NULL, NULL, NULL); + qemu_coroutine_enter(data->co, NULL); +} + +void coroutine_fn yield_until_fd_readable(int fd) +{ + FDYieldUntilData data; + + assert(qemu_in_coroutine()); + data.co = qemu_coroutine_self(); + data.fd = fd; + qemu_set_fd_handler(fd, fd_coroutine_enter, NULL, &data); + qemu_coroutine_yield(); +}