Blame 0004-char-Add-framework-for-a-write-unblocked-callback.patch

96a5f8
From f4be4da263d4bad7c600d847e13e69cca4ab08b6 Mon Sep 17 00:00:00 2001
96a5f8
From: Amit Shah <amit.shah@redhat.com>
96a5f8
Date: Mon, 21 Mar 2011 21:41:42 +0100
96a5f8
Subject: [PATCH] char: Add framework for a 'write unblocked' callback
96a5f8
96a5f8
The char layer can let users know that the driver will block on further
96a5f8
input.  For users interested in not blocking, they can assign a function
96a5f8
pointer that will be called back when the driver becomes writable.  This
96a5f8
patch just adds the function pointers to the CharDriverState structure,
96a5f8
future patches will enable the nonblocking and callback functionality.
96a5f8
96a5f8
Signed-off-by: Amit Shah <amit.shah@redhat.com>
96a5f8
Signed-off-by: Cole Robinson <crobinso@redhat.com>
96a5f8
---
96a5f8
 include/char/char.h | 4 ++++
96a5f8
 qemu-char.c         | 3 +++
96a5f8
 2 files changed, 7 insertions(+)
96a5f8
96a5f8
diff --git a/include/char/char.h b/include/char/char.h
96a5f8
index 3027cc1..2fee107 100644
96a5f8
--- a/include/char/char.h
96a5f8
+++ b/include/char/char.h
96a5f8
@@ -63,6 +63,9 @@ struct CharDriverState {
96a5f8
     IOEventHandler *chr_event;
96a5f8
     IOCanReadHandler *chr_can_read;
96a5f8
     IOReadHandler *chr_read;
96a5f8
+    IOHandler *chr_write_unblocked;
96a5f8
+    void (*chr_enable_write_fd_handler)(struct CharDriverState *chr);
96a5f8
+    void (*chr_disable_write_fd_handler)(struct CharDriverState *chr);
96a5f8
     void *handler_opaque;
96a5f8
     void (*chr_close)(struct CharDriverState *chr);
96a5f8
     void (*chr_accept_input)(struct CharDriverState *chr);
96a5f8
@@ -76,6 +79,7 @@ struct CharDriverState {
96a5f8
     int opened;
96a5f8
     int avail_connections;
96a5f8
     QemuOpts *opts;
96a5f8
+    bool write_blocked; /* Are we in a blocked state? */
96a5f8
     QTAILQ_ENTRY(CharDriverState) next;
96a5f8
 };
96a5f8
 
96a5f8
diff --git a/qemu-char.c b/qemu-char.c
96a5f8
index 5abb8b9..ce2eba8 100644
96a5f8
--- a/qemu-char.c
96a5f8
+++ b/qemu-char.c
96a5f8
@@ -211,11 +211,14 @@ void qemu_chr_add_handlers(CharDriverState *s,
96a5f8
     }
96a5f8
     s->chr_can_read = handlers->fd_can_read;
96a5f8
     s->chr_read = handlers->fd_read;
96a5f8
+    s->chr_write_unblocked = handlers->fd_write_unblocked;
96a5f8
     s->chr_event = handlers->fd_event;
96a5f8
     s->handler_opaque = opaque;
96a5f8
     if (s->chr_update_read_handler)
96a5f8
         s->chr_update_read_handler(s);
96a5f8
 
96a5f8
+    s->write_blocked = false;
96a5f8
+
96a5f8
     /* We're connecting to an already opened device, so let's make sure we
96a5f8
        also get the open event */
96a5f8
     if (s->opened) {