252f3a
>From daf37480ffe37b3e7a781ff010beb4fa89821c29 Mon Sep 17 00:00:00 2001
252f3a
From: Amit Shah <amit.shah@redhat.com>
252f3a
Date: Mon, 21 Mar 2011 21:41:42 +0100
252f3a
Subject: [PATCH 08/17] char: Add framework for a 'write unblocked' callback
252f3a
252f3a
The char layer can let users know that the driver will block on further
252f3a
input.  For users interested in not blocking, they can assign a function
252f3a
pointer that will be called back when the driver becomes writable.  This
252f3a
patch just adds the function pointers to the CharDriverState structure,
252f3a
future patches will enable the nonblocking and callback functionality.
252f3a
252f3a
Signed-off-by: Amit Shah <amit.shah@redhat.com>
252f3a
---
252f3a
 qemu-char.c |    3 +++
252f3a
 qemu-char.h |    5 +++++
252f3a
 2 files changed, 8 insertions(+), 0 deletions(-)
252f3a
252f3a
diff --git a/qemu-char.c b/qemu-char.c
252f3a
index 3a31d8b..ce76411 100644
252f3a
--- a/qemu-char.c
252f3a
+++ b/qemu-char.c
252f3a
@@ -206,11 +206,14 @@ void qemu_chr_add_handlers(CharDriverState *s,
252f3a
     }
252f3a
     s->chr_can_read = handlers->fd_can_read;
252f3a
     s->chr_read = handlers->fd_read;
252f3a
+    s->chr_write_unblocked = handlers->fd_write_unblocked;
252f3a
     s->chr_event = handlers->fd_event;
252f3a
     s->handler_opaque = opaque;
252f3a
     if (s->chr_update_read_handler)
252f3a
         s->chr_update_read_handler(s);
252f3a
 
252f3a
+    s->write_blocked = false;
252f3a
+
252f3a
     /* We're connecting to an already opened device, so let's make sure we
252f3a
        also get the open event */
252f3a
     if (s->opened) {
252f3a
diff --git a/qemu-char.h b/qemu-char.h
252f3a
index 185377c..bf06da0 100644
252f3a
--- a/qemu-char.h
252f3a
+++ b/qemu-char.h
252f3a
@@ -61,6 +61,9 @@ struct CharDriverState {
252f3a
     IOEventHandler *chr_event;
252f3a
     IOCanReadHandler *chr_can_read;
252f3a
     IOReadHandler *chr_read;
252f3a
+    IOHandler *chr_write_unblocked;
252f3a
+    void (*chr_enable_write_fd_handler)(struct CharDriverState *chr);
252f3a
+    void (*chr_disable_write_fd_handler)(struct CharDriverState *chr);
252f3a
     void *handler_opaque;
252f3a
     void (*chr_send_event)(struct CharDriverState *chr, int event);
252f3a
     void (*chr_close)(struct CharDriverState *chr);
252f3a
@@ -71,6 +74,8 @@ struct CharDriverState {
252f3a
     char *label;
252f3a
     char *filename;
252f3a
     int opened;
252f3a
+    /* Are we in a blocked state? */
252f3a
+    bool write_blocked;
252f3a
     QTAILQ_ENTRY(CharDriverState) next;
252f3a
 };
252f3a
 
252f3a
-- 
252f3a
1.7.3.2
252f3a