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)
{
}
#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)
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);
}
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);
}
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;
}