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

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