carlwgeorge / rpms / qemu

Forked from rpms/qemu a year ago
Clone
a7b9285
From 1f039120d2d1b4b97dbb92ec84492a7e917ab09e Mon Sep 17 00:00:00 2001
96a5f8d
From: Amit Shah <amit.shah@redhat.com>
96a5f8d
Date: Mon, 21 Mar 2011 20:32:58 +0100
96a5f8d
Subject: [PATCH] iohandlers: Add enable/disable_write_fd_handler() functions
96a5f8d
96a5f8d
These will be used to provide a cleaner API for the nonblocking case.
96a5f8d
96a5f8d
Signed-off-by: Amit Shah <amit.shah@redhat.com>
96a5f8d
Signed-off-by: Cole Robinson <crobinso@redhat.com>
96a5f8d
---
96a5f8d
 include/qemu/main-loop.h |  3 +++
96a5f8d
 iohandler.c              | 35 +++++++++++++++++++++++++++++++++++
96a5f8d
 2 files changed, 38 insertions(+)
96a5f8d
96a5f8d
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
96a5f8d
index e8059c3..faaf47d 100644
96a5f8d
--- a/include/qemu/main-loop.h
96a5f8d
+++ b/include/qemu/main-loop.h
96a5f8d
@@ -166,6 +166,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
96a5f8d
 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
96a5f8d
 typedef int IOCanReadHandler(void *opaque);
96a5f8d
 
96a5f8d
+void enable_write_fd_handler(int fd, IOHandler *fd_write);
96a5f8d
+void disable_write_fd_handler(int fd);
96a5f8d
+
96a5f8d
 /**
96a5f8d
  * qemu_set_fd_handler2: Register a file descriptor with the main loop
96a5f8d
  *
96a5f8d
diff --git a/iohandler.c b/iohandler.c
96a5f8d
index 2523adc..a49cfd4 100644
96a5f8d
--- a/iohandler.c
96a5f8d
+++ b/iohandler.c
96a5f8d
@@ -45,6 +45,41 @@ typedef struct IOHandlerRecord {
96a5f8d
 static QLIST_HEAD(, IOHandlerRecord) io_handlers =
96a5f8d
     QLIST_HEAD_INITIALIZER(io_handlers);
96a5f8d
 
96a5f8d
+static IOHandlerRecord *find_iohandler(int fd)
96a5f8d
+{
96a5f8d
+    IOHandlerRecord *ioh;
96a5f8d
+
96a5f8d
+    QLIST_FOREACH(ioh, &io_handlers, next) {
96a5f8d
+        if (ioh->fd == fd) {
96a5f8d
+            return ioh;
96a5f8d
+        }
96a5f8d
+    }
96a5f8d
+    return NULL;
96a5f8d
+}
96a5f8d
+
96a5f8d
+void enable_write_fd_handler(int fd, IOHandler *fd_write)
96a5f8d
+{
96a5f8d
+    IOHandlerRecord *ioh;
96a5f8d
+
96a5f8d
+    ioh = find_iohandler(fd);
96a5f8d
+    if (!ioh) {
96a5f8d
+        return;
96a5f8d
+    }
96a5f8d
+
96a5f8d
+    ioh->fd_write = fd_write;
96a5f8d
+}
96a5f8d
+
96a5f8d
+void disable_write_fd_handler(int fd)
96a5f8d
+{
96a5f8d
+    IOHandlerRecord *ioh;
96a5f8d
+
96a5f8d
+    ioh = find_iohandler(fd);
96a5f8d
+    if (!ioh) {
96a5f8d
+        return;
96a5f8d
+    }
96a5f8d
+
96a5f8d
+    ioh->fd_write = NULL;
96a5f8d
+}
96a5f8d
 
96a5f8d
 /* XXX: fd_read_poll should be suppressed, but an API change is
96a5f8d
    necessary in the character devices to suppress fd_can_read(). */