net: convert tap-win32 to NetClientInfo

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Mark McLoughlin 2009-11-25 18:49:05 +00:00 committed by Anthony Liguori
parent 3e35ba93ec
commit dca91811bc

View File

@ -630,25 +630,24 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,
/********************************************/ /********************************************/
typedef struct TAPState { typedef struct TAPState {
VLANClientState *vc; VLANClientState nc;
tap_win32_overlapped_t *handle; tap_win32_overlapped_t *handle;
} TAPState; } TAPState;
static void tap_cleanup(VLANClientState *vc) static void tap_cleanup(VLANClientState *nc)
{ {
TAPState *s = vc->opaque; TAPState *s = DO_UPCAST(TAPState, nc, nc);
qemu_del_wait_object(s->handle->tap_semaphore, NULL, NULL); qemu_del_wait_object(s->handle->tap_semaphore, NULL, NULL);
/* FIXME: need to kill thread and close file handle: /* FIXME: need to kill thread and close file handle:
tap_win32_close(s); tap_win32_close(s);
*/ */
qemu_free(s);
} }
static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
{ {
TAPState *s = vc->opaque; TAPState *s = DO_UPCAST(TAPState, nc, nc);
return tap_win32_write(s->handle, buf, size); return tap_win32_write(s->handle, buf, size);
} }
@ -662,33 +661,41 @@ static void tap_win32_send(void *opaque)
size = tap_win32_read(s->handle, &buf, max_size); size = tap_win32_read(s->handle, &buf, max_size);
if (size > 0) { if (size > 0) {
qemu_send_packet(s->vc, buf, size); qemu_send_packet(&s->nc, buf, size);
tap_win32_free_buffer(s->handle, buf); tap_win32_free_buffer(s->handle, buf);
} }
} }
static NetClientInfo net_tap_win32_info = {
.type = NET_CLIENT_TYPE_TAP,
.size = sizeof(TAPState),
.receive = tap_receive,
.cleanup = tap_cleanup,
};
static int tap_win32_init(VLANState *vlan, const char *model, static int tap_win32_init(VLANState *vlan, const char *model,
const char *name, const char *ifname) const char *name, const char *ifname)
{ {
VLANClientState *nc;
TAPState *s; TAPState *s;
tap_win32_overlapped_t *handle;
s = qemu_mallocz(sizeof(TAPState)); if (tap_win32_open(&handle, ifname) < 0) {
if (!s)
return -1;
if (tap_win32_open(&s->handle, ifname) < 0) {
printf("tap: Could not open '%s'\n", ifname); printf("tap: Could not open '%s'\n", ifname);
return -1; return -1;
} }
s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP, nc = qemu_new_net_client(&net_tap_win32_info, vlan, NULL, model, name);
vlan, NULL, model, name,
NULL, tap_receive,
NULL, NULL, tap_cleanup, s);
snprintf(s->vc->info_str, sizeof(s->vc->info_str), snprintf(s->nc.info_str, sizeof(s->nc.info_str),
"tap: ifname=%s", ifname); "tap: ifname=%s", ifname);
s = DO_UPCAST(TAPState, nc, nc);
s->handle = handle;
qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s); qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s);
return 0; return 0;
} }