From: Mark McLoughlin <markmc@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mark McLoughlin <markmc@redhat.com>
Subject: [Qemu-devel] [PATCH 3/8] net: add tap_read_poll() helper
Date: Thu, 18 Jun 2009 18:21:31 +0100 [thread overview]
Message-ID: <1245345696-20915-4-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1245345696-20915-3-git-send-email-markmc@redhat.com>
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>
---
net.c | 30 +++++++++++++++++++++++-------
1 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/net.c b/net.c
index 91c08bd..9005822 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;
}
--
1.6.0.6
next prev parent reply other threads:[~2009-06-18 17:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-18 17:21 [Qemu-devel] [PATCH 0/8] TUNSETSNDBUF - pushback to help UDP tx Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 1/8] net: add qemu_purge_queued_packets() Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 2/8] net: purge queued packets in tap_cleanup() Mark McLoughlin
2009-06-18 17:21 ` Mark McLoughlin [this message]
2009-06-18 17:21 ` [Qemu-devel] [PATCH 4/8] net: handle EAGAIN from tapfd write() Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 5/8] net: return TAPState from net_tap_init() Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 6/8] net: add '-net tap,sndbuf=nbytes' Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 7/8] net: add packet length to NetPacketSent callback Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 8/8] virtio-net: implement async packet sending Mark McLoughlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1245345696-20915-4-git-send-email-markmc@redhat.com \
--to=markmc@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).