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