Blame 0103-iohandlers-Add-enable-disable_write_fd_handler-funct.patch

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