render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

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

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