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