From patchwork Fri Apr 26 02:47:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pingfan liu X-Patchwork-Id: 239627 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 143452C011B for ; Fri, 26 Apr 2013 12:49:21 +1000 (EST) Received: from localhost ([::1]:44111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVYis-0002aQ-Kc for incoming@patchwork.ozlabs.org; Thu, 25 Apr 2013 22:49:18 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVYiI-0002V4-08 for qemu-devel@nongnu.org; Thu, 25 Apr 2013 22:48:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UVYiG-0007n5-IJ for qemu-devel@nongnu.org; Thu, 25 Apr 2013 22:48:41 -0400 Received: from mail-ie0-x233.google.com ([2607:f8b0:4001:c03::233]:58170) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVYiG-0007ml-Dr for qemu-devel@nongnu.org; Thu, 25 Apr 2013 22:48:40 -0400 Received: by mail-ie0-f179.google.com with SMTP id 16so4463466iea.10 for ; Thu, 25 Apr 2013 19:48:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=gh1BmPuWXRJv32XI9JsczN8Uv/FB4B0SWD7Xtw1WqNs=; b=mgvlws0gI3iZvIZH7v4puYlkRx3sNWv4maRFCpUIHBmo7apfrjoO5dwP6rdkK8Qfq1 QOuProV2/3tZ4lrEE7z6tTh7dHA4wbjzzHUEVnnFBpiMXY8+T7DazJ4UjXj5AjUAF1gT iIDrEe1kPNewSgxM0fFRKs7gseWFaaRPL82msTB7si836urPDCLkc+tpesH5PxdNXDD8 3Zp2Ch0lWEjMGQnTIug6Pluck5/QsMurblE+JXK9HA3OgCRzVCbIvTvf1R/ew1nCwdJN 4tAZTSJx0InSRnKbht0tEjAevXJERByinapssk0ga5XvlphSqPRpRyttjaNk40k+2e9Y naZg== X-Received: by 10.42.150.131 with SMTP id a3mr6707032icw.8.1366944519913; Thu, 25 Apr 2013 19:48:39 -0700 (PDT) Received: from localhost ([202.108.130.138]) by mx.google.com with ESMTPSA id wn10sm1114663igb.2.2013.04.25.19.48.34 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 25 Apr 2013 19:48:38 -0700 (PDT) From: Liu Ping Fan To: qemu-devel@nongnu.org Date: Fri, 26 Apr 2013 10:47:25 +0800 Message-Id: <1366944455-14239-5-git-send-email-qemulist@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1366944455-14239-1-git-send-email-qemulist@gmail.com> References: <1366944455-14239-1-git-send-email-qemulist@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c03::233 Cc: mdroth , Jan Kiszka , Stefan Hajnoczi , Anthony Liguori , Paolo Bonzini Subject: [Qemu-devel] [RFC PATCH v5 04/14] net: port vde onto GSource 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 From: Liu Ping Fan Signed-off-by: Liu Ping Fan --- net/vde.c | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-) diff --git a/net/vde.c b/net/vde.c index 4dea32d..6dbde04 100644 --- a/net/vde.c +++ b/net/vde.c @@ -30,10 +30,12 @@ #include "qemu-common.h" #include "qemu/option.h" #include "qemu/main-loop.h" +#include "util/event_gsource.h" typedef struct VDEState { NetClientState nc; VDECONN *vde; + EventGSource *nsrc; } VDEState; static void vde_to_qemu(void *opaque) @@ -60,20 +62,43 @@ static ssize_t vde_receive(NetClientState *nc, const uint8_t *buf, size_t size) return ret; } +static gboolean vde_handler(gpointer data) +{ + EventGSource *nsrc = (EventGSource *)data; + + if (nsrc->gfd.revents & G_IO_IN) { + vde_to_qemu(nsrc->opaque); + } + return true; +} + static void vde_cleanup(NetClientState *nc) { VDEState *s = DO_UPCAST(VDEState, nc, nc); - qemu_set_fd_handler(vde_datafd(s->vde), NULL, NULL, NULL); + event_source_release(s->nsrc); vde_close(s->vde); } +static void vde_bind_ctx(NetClientState *nc, GMainContext *ctx) +{ + VDEState *s = DO_UPCAST(VDEState, nc, nc); + + g_source_attach(&s->nsrc->source, ctx); +} + static NetClientInfo net_vde_info = { .type = NET_CLIENT_OPTIONS_KIND_VDE, .size = sizeof(VDEState), .receive = vde_receive, .cleanup = vde_cleanup, + .bind_ctx = vde_bind_ctx, }; +static gushort readable(void *opaque) +{ + return G_IO_IN; +} + static int net_vde_init(NetClientState *peer, const char *model, const char *name, const char *sock, int port, const char *group, int mode) @@ -104,7 +129,9 @@ static int net_vde_init(NetClientState *peer, const char *model, s->vde = vde; - qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); + s->nsrc = event_source_new(vde_datafd(vde), vde_handler, s); + s->nsrc->readable = readable; + nc->info->bind_ctx(nc, NULL); return 0; }