Blame 0106-char-Equip-the-unix-tcp-backend-to-handle-nonblockin.patch

6986e1
From e8a6c8da28eb73704099b4ae2172bca7fa4d0bd7 Mon Sep 17 00:00:00 2001
22d63f
From: Amit Shah <amit.shah@redhat.com>
22d63f
Date: Mon, 21 Mar 2011 22:02:47 +0100
22d63f
Subject: [PATCH] char: Equip the unix/tcp backend to handle nonblocking
22d63f
 writes#
22d63f
22d63f
Now that the infrastructure is in place to return -EAGAIN to callers,
22d63f
individual char drivers can set their update_fd_handlers() function to
22d63f
set or remove an fd's write handler.  This handler checks if the driver
22d63f
became writable.
22d63f
22d63f
A generic callback routine is used for unblocking writes and letting
22d63f
users of chardevs know that a driver became writable again.
22d63f
22d63f
Signed-off-by: Amit Shah <amit.shah@redhat.com>
22d63f
Signed-off-by: Cole Robinson <crobinso@redhat.com>
22d63f
---
22d63f
 qemu-char.c | 34 ++++++++++++++++++++++++++++++++++
22d63f
 1 file changed, 34 insertions(+)
22d63f
22d63f
diff --git a/qemu-char.c b/qemu-char.c
22d63f
index 53803a3..e7cd42a 100644
22d63f
--- a/qemu-char.c
22d63f
+++ b/qemu-char.c
22d63f
@@ -106,6 +106,19 @@
22d63f
 static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs =
22d63f
     QTAILQ_HEAD_INITIALIZER(chardevs);
22d63f
 
22d63f
+/*
22d63f
+ * Generic routine that gets called when chardev becomes writable.
22d63f
+ * Lets chardev user know it's OK to send more data.
22d63f
+ */
22d63f
+static void char_write_unblocked(void *opaque)
22d63f
+{
22d63f
+    CharDriverState *chr = opaque;
22d63f
+
22d63f
+    chr->write_blocked = false;
22d63f
+    chr->chr_disable_write_fd_handler(chr);
22d63f
+    chr->chr_write_unblocked(chr->handler_opaque);
22d63f
+}
22d63f
+
22d63f
 void qemu_chr_be_event(CharDriverState *s, int event)
22d63f
 {
22d63f
     /* Keep track if the char device is open */
22d63f
@@ -2508,6 +2521,25 @@ static void tcp_chr_close(CharDriverState *chr)
22d63f
     qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
22d63f
 }
22d63f
 
22d63f
+static void tcp_enable_write_fd_handler(CharDriverState *chr)
22d63f
+{
22d63f
+    TCPCharDriver *s = chr->opaque;
22d63f
+
22d63f
+    /*
22d63f
+     * This function is called only after tcp_chr_connect() is called
22d63f
+     * (either in 'server' mode or client mode.  So we're sure of
22d63f
+     * s->fd being initialised.
22d63f
+     */
22d63f
+    enable_write_fd_handler(s->fd, char_write_unblocked);
22d63f
+}
22d63f
+
22d63f
+static void tcp_disable_write_fd_handler(CharDriverState *chr)
22d63f
+{
22d63f
+    TCPCharDriver *s = chr->opaque;
22d63f
+
22d63f
+    disable_write_fd_handler(s->fd);
22d63f
+}
22d63f
+
22d63f
 static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
22d63f
 {
22d63f
     CharDriverState *chr = NULL;
22d63f
@@ -2563,6 +2595,8 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
22d63f
     chr->chr_close = tcp_chr_close;
22d63f
     chr->get_msgfd = tcp_get_msgfd;
22d63f
     chr->chr_add_client = tcp_chr_add_client;
22d63f
+    chr->chr_enable_write_fd_handler = tcp_enable_write_fd_handler;
22d63f
+    chr->chr_disable_write_fd_handler = tcp_disable_write_fd_handler;
22d63f
 
22d63f
     if (is_listen) {
22d63f
         s->listen_fd = fd;
22d63f
-- 
6986e1
1.8.1
22d63f