5e10b1
From cb93720645e20825259dbb4d2f833b05a98e3062 Mon Sep 17 00:00:00 2001
3f1f29
From: Amit Shah <amit.shah@redhat.com>
3f1f29
Date: Mon, 21 Mar 2011 20:32:58 +0100
5e10b1
Subject: [PATCH 03/13] iohandlers: Add enable/disable_write_fd_handler()
3f1f29
 functions
3f1f29
3f1f29
These will be used to provide a cleaner API for the nonblocking case.
3f1f29
3f1f29
Signed-off-by: Amit Shah <amit.shah@redhat.com>
3f1f29
---
3f1f29
 iohandler.c |   35 +++++++++++++++++++++++++++++++++++
3f1f29
 qemu-char.h |    3 +++
3f1f29
 2 files changed, 38 insertions(+), 0 deletions(-)
3f1f29
3f1f29
diff --git a/iohandler.c b/iohandler.c
3f1f29
index 2b82421..8e6628b 100644
3f1f29
--- a/iohandler.c
3f1f29
+++ b/iohandler.c
3f1f29
@@ -44,6 +44,41 @@ typedef struct IOHandlerRecord {
3f1f29
 static QLIST_HEAD(, IOHandlerRecord) io_handlers =
3f1f29
     QLIST_HEAD_INITIALIZER(io_handlers);
3f1f29
 
3f1f29
+static IOHandlerRecord *find_iohandler(int fd)
3f1f29
+{
3f1f29
+    IOHandlerRecord *ioh;
3f1f29
+
3f1f29
+    QLIST_FOREACH(ioh, &io_handlers, next) {
3f1f29
+        if (ioh->fd == fd) {
3f1f29
+            return ioh;
3f1f29
+        }
3f1f29
+    }
3f1f29
+    return NULL;
3f1f29
+}
3f1f29
+
3f1f29
+void enable_write_fd_handler(int fd, IOHandler *fd_write)
3f1f29
+{
3f1f29
+    IOHandlerRecord *ioh;
3f1f29
+
3f1f29
+    ioh = find_iohandler(fd);
3f1f29
+    if (!ioh) {
3f1f29
+        return;
3f1f29
+    }
3f1f29
+
3f1f29
+    ioh->fd_write = fd_write;
3f1f29
+}
3f1f29
+
3f1f29
+void disable_write_fd_handler(int fd)
3f1f29
+{
3f1f29
+    IOHandlerRecord *ioh;
3f1f29
+
3f1f29
+    ioh = find_iohandler(fd);
3f1f29
+    if (!ioh) {
3f1f29
+        return;
3f1f29
+    }
3f1f29
+
3f1f29
+    ioh->fd_write = NULL;
3f1f29
+}
3f1f29
 
3f1f29
 /* XXX: fd_read_poll should be suppressed, but an API change is
3f1f29
    necessary in the character devices to suppress fd_can_read(). */
3f1f29
diff --git a/qemu-char.h b/qemu-char.h
5e10b1
index b8372ea..9fe1b82 100644
3f1f29
--- a/qemu-char.h
3f1f29
+++ b/qemu-char.h
5e10b1
@@ -123,6 +123,9 @@ size_t qemu_chr_mem_osize(const CharDriverState *chr);
3f1f29
 
3f1f29
 /* async I/O support */
3f1f29
 
3f1f29
+void enable_write_fd_handler(int fd, IOHandler *fd_write);
3f1f29
+void disable_write_fd_handler(int fd);
3f1f29
+
3f1f29
 int qemu_set_fd_handler2(int fd,
3f1f29
                          IOCanReadHandler *fd_read_poll,
3f1f29
                          IOHandler *fd_read,
3f1f29
-- 
3f1f29
1.7.5.1
3f1f29