qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amit Shah <amit.shah@redhat.com>
To: qemu list <qemu-devel@nongnu.org>
Cc: Amit Shah <amit.shah@redhat.com>,
	Paul Brook <paul@codesourcery.com>,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 5/5] char: Equip the unix/tcp backend to handle nonblocking writes
Date: Tue, 11 Jan 2011 16:40:34 +0530	[thread overview]
Message-ID: <2e63b173956da74c9759b57bddb9d2f01053f8b2.1294743490.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1294743490.git.amit.shah@redhat.com>
In-Reply-To: <cover.1294743490.git.amit.shah@redhat.com>

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>
---
 qemu-char.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 6e02334..55d442d 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -235,6 +235,19 @@ static int char_remove_fd_handlers(int fd)
     return qemu_set_fd_handler2(fd, NULL, NULL, NULL, NULL);
 }
 
+/*
+ * 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->update_fd_handlers(chr, false);
+    chr->chr_write_unblocked(chr->handler_opaque);
+}
+
 static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
 {
     return len;
@@ -2269,6 +2282,19 @@ static void tcp_chr_close(CharDriverState *chr)
     qemu_chr_event(chr, CHR_EVENT_CLOSED);
 }
 
+static void tcp_update_fd_handlers(CharDriverState *chr, bool poll_out)
+{
+    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.
+     */
+    char_set_fd_handlers(s->fd, tcp_chr_read_poll, tcp_chr_read,
+                         char_write_unblocked, chr, poll_out);
+}
+
 static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
 {
     CharDriverState *chr = NULL;
@@ -2321,6 +2347,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
     chr->chr_write = tcp_chr_write;
     chr->chr_close = tcp_chr_close;
     chr->get_msgfd = tcp_get_msgfd;
+    chr->update_fd_handlers = tcp_update_fd_handlers;
 
     if (is_listen) {
         s->listen_fd = fd;
-- 
1.7.3.4

  parent reply	other threads:[~2011-01-11 11:11 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-11 11:10 [Qemu-devel] [PATCH v9 0/5] char: Add support for nonblocking writes Amit Shah
2011-01-11 11:10 ` [Qemu-devel] [PATCH 1/5] char: Add a QemuChrHandlers struct to initialise chardev handlers Amit Shah
2011-01-11 14:17   ` [Qemu-devel] " Gerd Hoffmann
2011-01-11 17:13   ` [Qemu-devel] " Blue Swirl
2011-01-12  6:07     ` Amit Shah
2011-01-12 18:01       ` Michael Roth
2011-01-12 19:03         ` Blue Swirl
2011-01-13  6:14           ` Amit Shah
2011-01-13 21:29             ` Blue Swirl
2011-01-11 11:10 ` [Qemu-devel] [PATCH 2/5] char: Introduce char_set/remove_fd_handlers() Amit Shah
2011-01-11 14:39   ` [Qemu-devel] " Gerd Hoffmann
2011-01-11 15:38     ` Amit Shah
2011-01-11 15:54       ` Gerd Hoffmann
2011-01-11 17:23         ` Amit Shah
2011-01-12  9:11           ` Gerd Hoffmann
2011-01-11 11:10 ` [Qemu-devel] [PATCH 3/5] char: Add framework for a 'write unblocked' callback Amit Shah
2011-01-11 14:43   ` [Qemu-devel] " Gerd Hoffmann
2011-01-11 11:10 ` [Qemu-devel] [PATCH 4/5] char: Update send_all() to handle nonblocking chardev write requests Amit Shah
2011-01-11 11:10 ` Amit Shah [this message]
2011-01-11 13:38   ` [Qemu-devel] Re: [PATCH 5/5] char: Equip the unix/tcp backend to handle nonblocking writes Paolo Bonzini
2011-01-12  6:16     ` Amit Shah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e63b173956da74c9759b57bddb9d2f01053f8b2.1294743490.git.amit.shah@redhat.com \
    --to=amit.shah@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).