From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=36698 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNjPy-0007LW-68 for qemu-devel@nongnu.org; Wed, 01 Dec 2010 04:56:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PNjPw-0007Us-N4 for qemu-devel@nongnu.org; Wed, 01 Dec 2010 04:56:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:8568) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PNjPw-0007Uf-Ch for qemu-devel@nongnu.org; Wed, 01 Dec 2010 04:56:04 -0500 From: Amit Shah Date: Wed, 1 Dec 2010 15:24:28 +0530 Message-Id: <88e62902315294e29e88da2c54872adb54a1a617.1291196789.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH v8 6/7] char: Equip the unix/tcp backend to handle nonblocking writes List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu list Cc: Amit Shah , Gerd Hoffmann , Juan Quintela 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 --- qemu-char.c | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index a24c4c2..e624600 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; @@ -2263,6 +2276,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; @@ -2315,6 +2341,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.2