X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qemu-coroutine-io.c;h=054ca70627e386198314deb616cfbf47b144619e;hb=b15654c21acef4d2bc17e6ac528c6c93abbb7e1e;hp=e8ad1a40110e136e64a92ec1a58c0aca49cf851c;hpb=bb5801f551ee8591d576d87a9290af297998e322;p=qemu.git diff --git a/qemu-coroutine-io.c b/qemu-coroutine-io.c index e8ad1a401..054ca7062 100644 --- a/qemu-coroutine-io.c +++ b/qemu-coroutine-io.c @@ -26,6 +26,7 @@ #include "qemu/sockets.h" #include "block/coroutine.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(); +}