From patchwork Tue Feb 22 10:18:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 83952 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B9E52B7082 for ; Tue, 22 Feb 2011 21:29:30 +1100 (EST) Received: from localhost ([127.0.0.1]:41902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PrpUj-0006pr-40 for incoming@patchwork.ozlabs.org; Tue, 22 Feb 2011 05:29:25 -0500 Received: from [140.186.70.92] (port=39190 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PrpKu-0000PX-RE for qemu-devel@nongnu.org; Tue, 22 Feb 2011 05:19:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PrpKt-0005gA-Fj for qemu-devel@nongnu.org; Tue, 22 Feb 2011 05:19:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48545) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PrpKt-0005g6-0z for qemu-devel@nongnu.org; Tue, 22 Feb 2011 05:19:15 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1MAJC1i001211 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 22 Feb 2011 05:19:12 -0500 Received: from localhost (ovpn-113-98.phx2.redhat.com [10.3.113.98]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p1MAJ9gk027566; Tue, 22 Feb 2011 05:19:10 -0500 From: Amit Shah To: qemu list Date: Tue, 22 Feb 2011 15:48:32 +0530 Message-Id: <8bbf9ec7ef689ea8d54e7f1aa2f420cc92bc3ae1.1298369272.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Amit Shah , Gerd Hoffmann Subject: [Qemu-devel] [PATCH 3/7] char: tcp: Use new iohandler api X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Update the tcp code to use the new iohandler api. The change is mostly mechanical with a new iohandler function calling the older functions depending on the value of the 'mask' field. Signed-off-by: Amit Shah --- qemu-char.c | 48 ++++++++++++++++++++++++++++++++++++------------ 1 files changed, 36 insertions(+), 12 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index bd4e944..ba58c18 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "iohandler.h" #include "qemu-common.h" #include "net.h" #include "monitor.h" @@ -1909,7 +1910,7 @@ typedef struct { int msgfd; } TCPCharDriver; -static void tcp_chr_accept(void *opaque); +static int tcp_accept_handler(void *opaque, unsigned int mask); static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len) { @@ -2064,9 +2065,10 @@ static void tcp_chr_read(void *opaque) /* connection closed */ s->connected = 0; if (s->listen_fd >= 0) { - qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr); + assign_iohandler(s->listen_fd, tcp_accept_handler, IOH_MASK_READ, + chr); } - qemu_set_fd_handler(s->fd, NULL, NULL, NULL); + remove_iohandler(s->fd); closesocket(s->fd); s->fd = -1; qemu_chr_event(chr, CHR_EVENT_CLOSED); @@ -2078,6 +2080,22 @@ static void tcp_chr_read(void *opaque) } } +static int tcp_iohandler(void *opaque, unsigned int mask) +{ + int ret; + + ret = 0; + switch(mask) { + case IOH_MASK_CAN_READ: + ret = tcp_chr_read_poll(opaque); + break; + case IOH_MASK_READ: + tcp_chr_read(opaque); + break; + } + return ret; +} + #ifndef _WIN32 CharDriverState *qemu_chr_open_eventfd(int eventfd) { @@ -2091,8 +2109,8 @@ static void tcp_chr_connect(void *opaque) TCPCharDriver *s = chr->opaque; s->connected = 1; - qemu_set_fd_handler2(s->fd, tcp_chr_read_poll, - tcp_chr_read, NULL, chr); + assign_iohandler(s->fd, tcp_iohandler, IOH_MASK_CAN_READ|IOH_MASK_READ, + chr); qemu_chr_generic_open(chr); } @@ -2117,7 +2135,7 @@ static void socket_set_nodelay(int fd) setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val)); } -static void tcp_chr_accept(void *opaque) +static int tcp_accept_handler(void *opaque, unsigned int mask) { CharDriverState *chr = opaque; TCPCharDriver *s = chr->opaque; @@ -2129,6 +2147,10 @@ static void tcp_chr_accept(void *opaque) socklen_t len; int fd; + if (!(mask & IOH_MASK_READ)) { + return 0; + } + for(;;) { #ifndef _WIN32 if (s->is_unix) { @@ -2142,7 +2164,7 @@ static void tcp_chr_accept(void *opaque) } fd = qemu_accept(s->listen_fd, addr, &len); if (fd < 0 && errno != EINTR) { - return; + return 0; } else if (fd >= 0) { if (s->do_telnetopt) tcp_chr_telnet_init(fd); @@ -2153,19 +2175,21 @@ static void tcp_chr_accept(void *opaque) if (s->do_nodelay) socket_set_nodelay(fd); s->fd = fd; - qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL); + remove_iohandler(s->listen_fd); tcp_chr_connect(chr); + + return 0; } static void tcp_chr_close(CharDriverState *chr) { TCPCharDriver *s = chr->opaque; if (s->fd >= 0) { - qemu_set_fd_handler(s->fd, NULL, NULL, NULL); + remove_iohandler(s->fd); closesocket(s->fd); } if (s->listen_fd >= 0) { - qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL); + remove_iohandler(s->listen_fd); closesocket(s->listen_fd); } qemu_free(s); @@ -2227,7 +2251,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts) if (is_listen) { s->listen_fd = fd; - qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr); + assign_iohandler(s->listen_fd, tcp_accept_handler, IOH_MASK_READ, chr); if (is_telnet) s->do_telnetopt = 1; @@ -2257,7 +2281,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts) if (is_listen && is_waitconnect) { printf("QEMU waiting for connection on: %s\n", chr->filename); - tcp_chr_accept(chr); + tcp_accept_handler(chr, IOH_MASK_READ); socket_set_nonblock(s->listen_fd); } return chr;