[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1 03/14] net: port vde onto GSource
From: |
Liu Ping Fan |
Subject: |
[Qemu-devel] [PATCH v1 03/14] net: port vde onto GSource |
Date: |
Tue, 7 May 2013 13:46:51 +0800 |
From: Liu Ping Fan <address@hidden>
Signed-off-by: Liu Ping Fan <address@hidden>
---
net/vde.c | 31 +++++++++++++++++++++++++++++--
1 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/net/vde.c b/net/vde.c
index 4dea32d..fe763dd 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 | G_IO_HUP | G_IO_ERR)) {
+ 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 | G_IO_HUP | G_IO_ERR;
+}
+
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;
}
--
1.7.4.4
- [Qemu-devel] [PATCH v1 00/14] port network layer onto glib, Liu Ping Fan, 2013/05/07
- [Qemu-devel] [PATCH v1 01/14] util: introduce gsource event abstraction, Liu Ping Fan, 2013/05/07
- [Qemu-devel] [PATCH v1 02/14] net: introduce bind_ctx to NetClientInfo, Liu Ping Fan, 2013/05/07
- [Qemu-devel] [PATCH v1 03/14] net: port vde onto GSource,
Liu Ping Fan <=
- [Qemu-devel] [PATCH v1 04/14] net: port socket to GSource, Liu Ping Fan, 2013/05/07
- [Qemu-devel] [PATCH v1 05/14] net: port tap onto GSource, Liu Ping Fan, 2013/05/07
- [Qemu-devel] [PATCH v1 06/14] net: port tap-win32 onto GSource, Liu Ping Fan, 2013/05/07
- [Qemu-devel] [PATCH v1 07/14] net: hub use lock to protect ports list, Liu Ping Fan, 2013/05/07
- [Qemu-devel] [PATCH v1 08/14] net: introduce lock to protect NetQueue, Liu Ping Fan, 2013/05/07
- [Qemu-devel] [PATCH v1 09/14] net: introduce lock to protect NetClientState's peer's access, Liu Ping Fan, 2013/05/07
- [Qemu-devel] [PATCH v1 10/14] net: make netclient re-entrant with refcnt, Liu Ping Fan, 2013/05/07