aboutsummaryrefslogtreecommitdiff
path: root/net.c
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2009-06-18 18:21:31 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2009-06-22 10:15:30 -0500
commitb664e3673c6c2ca228ce025292e32b34f73df5f5 (patch)
tree0e9aabd57605f615b108c4972f4f7b79767867f8 /net.c
parentb9adce2c833fae930f5bede2b8a3357697984e8c (diff)
downloadqemu-b664e3673c6c2ca228ce025292e32b34f73df5f5.zip
qemu-b664e3673c6c2ca228ce025292e32b34f73df5f5.tar.gz
qemu-b664e3673c6c2ca228ce025292e32b34f73df5f5.tar.bz2
net: add tap_read_poll() helper
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 <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'net.c')
-rw-r--r--net.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/net.c b/net.c
index eb26cd4..8e75a29 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;
}