@@ -30,7 +30,9 @@
#include <stddef.h>
#include <stdint.h>
+#include <unistd.h>
#include <pthread.h>
+#include <sys/eventfd.h>
#include "qom/object.h"
#include "qemu/thread.h"
@@ -147,4 +149,11 @@ void mpqemu_destroy_channel(MPQemuChannel *chan);
void mpqemu_link_set_callback(MPQemuLinkState *s, mpqemu_link_callback callback);
void mpqemu_start_coms(MPQemuLinkState *s);
+#define GET_REMOTE_WAIT eventfd(0, 0)
+#define PUT_REMOTE_WAIT(wait) close(wait)
+#define PROXY_LINK_WAIT_DONE 1
+
+uint64_t wait_for_remote(int efd);
+void notify_proxy(int fd, uint64_t val);
+
#endif
@@ -231,6 +231,46 @@ int mpqemu_msg_recv(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *chan)
return rc;
}
+uint64_t wait_for_remote(int efd)
+{
+ struct pollfd pfd = { .fd = efd, .events = POLLIN };
+ uint64_t val;
+ int ret;
+
+ ret = poll(&pfd, 1, 1000);
+
+ switch (ret) {
+ case 0:
+ qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: Timed out\n");
+ /* TODO: Kick-off error recovery */
+ return ULLONG_MAX;
+ case -1:
+ qemu_log_mask(LOG_REMOTE_DEBUG, "Poll error wait_for_remote: %s\n",
+ strerror(errno));
+ return ULLONG_MAX;
+ default:
+ if (read(efd, &val, sizeof(val)) == -1) {
+ qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: %s\n",
+ strerror(errno));
+ return ULLONG_MAX;
+ }
+ }
+
+ val = (val == ULLONG_MAX) ? val : (val - 1);
+
+ return val;
+}
+
+void notify_proxy(int efd, uint64_t val)
+{
+ val = (val == ULLONG_MAX) ? val : (val + 1);
+
+ if (write(efd, &val, sizeof(val)) == -1) {
+ qemu_log_mask(LOG_REMOTE_DEBUG, "Error notify_proxy: %s\n",
+ strerror(errno));
+ }
+}
+
static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout)
{
g_assert(timeout);