From patchwork Wed Jun 10 08:59:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 482552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 735F41401CB for ; Wed, 10 Jun 2015 19:01:18 +1000 (AEST) Received: from localhost ([::1]:38443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2bsq-0003kG-J6 for incoming@patchwork.ozlabs.org; Wed, 10 Jun 2015 05:01:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2bs6-0002XW-Ex for qemu-devel@nongnu.org; Wed, 10 Jun 2015 05:00:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z2bs2-0005A1-BB for qemu-devel@nongnu.org; Wed, 10 Jun 2015 05:00:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2brw-00050n-4b; Wed, 10 Jun 2015 05:00:20 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 934A72CD81D; Wed, 10 Jun 2015 09:00:19 +0000 (UTC) Received: from ad.nay.redhat.com (dhcp-14-104.nay.redhat.com [10.66.14.104]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5A8xqh3006136; Wed, 10 Jun 2015 05:00:16 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 10 Jun 2015 16:59:48 +0800 Message-Id: <1433926791-10580-7-git-send-email-famz@redhat.com> In-Reply-To: <1433926791-10580-1-git-send-email-famz@redhat.com> References: <1433926791-10580-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , qemu-block@nongnu.org, Stefan Weil , Stefan Hajnoczi , Jan Kiszka , Paolo Bonzini Subject: [Qemu-devel] [PATCH 6/9] slirp: Move icmp socket to iohandler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Where the fd was added, compare the events with so->poll_events and call qemu_set_fd_handler() to update if it's changed. Where the fd was not added, call qemu_set_fd_handler() to remove it. Update slirp->do_slowtimo with a return value. For simplicity, G_IO_HUP and G_IO_ERR are unnecessary to be explicitly stated here, because they're implied in qemu_set_fd_handler. For poll part, iohandler will call the read handler when there is an event, so the check in slirp_pollfds_poll() is removed. Signed-off-by: Fam Zheng --- slirp/slirp.c | 83 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/slirp/slirp.c b/slirp/slirp.c index 25cdca6..f648e6c 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -286,6 +286,44 @@ static void slirp_update_timeout(uint32_t *timeout) *timeout = t; } +static void slirp_icmp_read(void *opaque) +{ + struct socket *so = opaque; + icmp_receive(so); +} + +static bool slirp_poll_update_icmp(struct socket *so) +{ + bool ret = false; + bool old, new; + /* + * See if it's timed out + */ + if (so->so_expire) { + if (so->so_expire <= curtime) { + icmp_detach(so); + qemu_set_fd_handler(so->s, NULL, NULL, NULL); + return ret; + } else { + ret = true; /* Let socket expire */ + } + } + + old = so->poll_events == G_IO_IN; + new = !!(so->so_state & SS_ISFCONNECTED); + if (old != new) { + /* Need update */ + if (new) { + so->poll_events = G_IO_IN; + qemu_set_fd_handler(so->s, slirp_icmp_read, NULL, so); + } else { + so->poll_events = 0; + qemu_set_fd_handler(so->s, NULL, NULL, NULL); + } + } + return ret; +} + void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout) { Slirp *slirp; @@ -431,29 +469,7 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout) for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so_next) { so_next = so->so_next; - - so->pollfds_idx = -1; - - /* - * See if it's timed out - */ - if (so->so_expire) { - if (so->so_expire <= curtime) { - icmp_detach(so); - continue; - } else { - slirp->do_slowtimo = true; /* Let socket expire */ - } - } - - if (so->so_state & SS_ISFCONNECTED) { - GPollFD pfd = { - .fd = so->s, - .events = G_IO_IN | G_IO_HUP | G_IO_ERR, - }; - so->pollfds_idx = pollfds->len; - g_array_append_val(pollfds, pfd); - } + slirp->do_slowtimo |= slirp_poll_update_icmp(so); } } slirp_update_timeout(timeout); @@ -602,27 +618,6 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error) sorecvfrom(so); } } - - /* - * Check incoming ICMP relies. - */ - for (so = slirp->icmp.so_next; so != &slirp->icmp; - so = so_next) { - int revents; - - so_next = so->so_next; - - revents = 0; - if (so->pollfds_idx != -1) { - revents = g_array_index(pollfds, GPollFD, - so->pollfds_idx).revents; - } - - if (so->s != -1 && - (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) { - icmp_receive(so); - } - } } if_start(slirp);