From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MHLJ2-0006Wb-R1 for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:44 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MHLIx-0006Ok-15 for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:43 -0400 Received: from [199.232.76.173] (port=43808 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MHLIw-0006OF-Pw for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:38 -0400 Received: from mail02.svc.cra.dublin.eircom.net ([159.134.118.18]:44880) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MHLIw-0008SY-8w for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:38 -0400 From: Mark McLoughlin Date: Thu, 18 Jun 2009 18:21:31 +0100 Message-Id: <1245345696-20915-4-git-send-email-markmc@redhat.com> In-Reply-To: <1245345696-20915-3-git-send-email-markmc@redhat.com> References: <1245345696-20915-1-git-send-email-markmc@redhat.com> <1245345696-20915-2-git-send-email-markmc@redhat.com> <1245345696-20915-3-git-send-email-markmc@redhat.com> Subject: [Qemu-devel] [PATCH 3/8] net: add tap_read_poll() helper List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Mark McLoughlin Add a helper to enable/disable the read polling on tapfd. We need this, because we want to start write polling on the tapfd too and enable/disable both types of polling independently. Signed-off-by: Mark McLoughlin --- net.c | 30 +++++++++++++++++++++++------- 1 files changed, 23 insertions(+), 7 deletions(-) diff --git a/net.c b/net.c index 91c08bd..9005822 100644 --- a/net.c +++ b/net.c @@ -1043,10 +1043,29 @@ typedef struct TAPState { char down_script[1024]; char down_script_arg[128]; uint8_t buf[4096]; + unsigned int read_poll : 1; } TAPState; static int launch_script(const char *setup_script, const char *ifname, int fd); +static int tap_can_send(void *opaque); +static void tap_send(void *opaque); + +static void tap_update_fd_handler(TAPState *s) +{ + qemu_set_fd_handler2(s->fd, + s->read_poll ? tap_can_send : NULL, + s->read_poll ? tap_send : NULL, + NULL, + s); +} + +static void tap_read_poll(TAPState *s, int enable) +{ + s->read_poll = !!enable; + tap_update_fd_handler(s); +} + static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov, int iovcnt) { @@ -1097,13 +1116,10 @@ static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen) } #endif -static void tap_send(void *opaque); - static void tap_send_completed(VLANClientState *vc) { TAPState *s = vc->opaque; - - qemu_set_fd_handler2(s->fd, tap_can_send, tap_send, NULL, s); + tap_read_poll(s, 1); } static void tap_send(void *opaque) @@ -1119,7 +1135,7 @@ static void tap_send(void *opaque) size = qemu_send_packet_async(s->vc, s->buf, size, tap_send_completed); if (size == 0) { - qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); + tap_read_poll(s, 0); } } while (size > 0); } @@ -1133,7 +1149,7 @@ static void tap_cleanup(VLANClientState *vc) if (s->down_script[0]) launch_script(s->down_script, s->down_script_arg, s->fd); - qemu_set_fd_handler(s->fd, NULL, NULL, NULL); + tap_read_poll(s, 0); close(s->fd); qemu_free(s); } @@ -1151,7 +1167,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, s->fd = fd; s->vc = qemu_new_vlan_client(vlan, model, name, NULL, tap_receive, tap_receive_iov, tap_cleanup, s); - qemu_set_fd_handler2(s->fd, tap_can_send, tap_send, NULL, s); + tap_read_poll(s, 1); snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd); return s; } -- 1.6.0.6