From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, Stefan Weil <sw@weilnetz.de>,
Stefan Hajnoczi <stefanha@redhat.com>,
Jan Kiszka <jan.kiszka@siemens.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH 7/9] slirp: Move udb socket to iohandler
Date: Wed, 10 Jun 2015 16:59:49 +0800 [thread overview]
Message-ID: <1433926791-10580-8-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1433926791-10580-1-git-send-email-famz@redhat.com>
This change is a replicate of the previous one.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
slirp/slirp.c | 95 ++++++++++++++++++++++++-----------------------------------
1 file changed, 39 insertions(+), 56 deletions(-)
diff --git a/slirp/slirp.c b/slirp/slirp.c
index f648e6c..a031240 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -286,6 +286,44 @@ static void slirp_update_timeout(uint32_t *timeout)
*timeout = t;
}
+static void slirp_udb_read(void *opaque)
+{
+ struct socket *so = opaque;
+ sorecvfrom(so);
+}
+
+static bool slirp_poll_update_udb(struct socket *so)
+{
+ bool ret = false;
+ bool old, new;
+ /*
+ * See if it's timed out
+ */
+ if (so->so_expire) {
+ if (so->so_expire <= curtime) {
+ udp_detach(so);
+ qemu_set_fd_handler(so->s, NULL, NULL, NULL);
+ return ret;
+ } else {
+ ret = true;
+ }
+ }
+
+ new = so->so_state & SS_ISFCONNECTED && so->so_queued <= 4;
+ old = so->poll_events == G_IO_IN;
+ if (old != new) {
+ /* Need update */
+ if (new) {
+ so->poll_events = G_IO_IN;
+ qemu_set_fd_handler(so->s, slirp_udb_read, NULL, so);
+ } else {
+ so->poll_events = 0;
+ qemu_set_fd_handler(so->s, NULL, NULL, NULL);
+ }
+ }
+ return ret;
+}
+
static void slirp_icmp_read(void *opaque)
{
struct socket *so = opaque;
@@ -428,39 +466,7 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
for (so = slirp->udb.so_next; so != &slirp->udb;
so = so_next) {
so_next = so->so_next;
-
- so->pollfds_idx = -1;
-
- /*
- * See if it's timed out
- */
- if (so->so_expire) {
- if (so->so_expire <= curtime) {
- udp_detach(so);
- continue;
- } else {
- slirp->do_slowtimo = true; /* Let socket expire */
- }
- }
-
- /*
- * When UDP packets are received from over the
- * link, they're sendto()'d straight away, so
- * no need for setting for writing
- * Limit the number of packets queued by this session
- * to 4. Note that even though we try and limit this
- * to 4 packets, the session could have more queued
- * if the packets needed to be fragmented
- * (XXX <= 4 ?)
- */
- if ((so->so_state & SS_ISFCONNECTED) && so->so_queued <= 4) {
- GPollFD pfd = {
- .fd = so->s,
- .events = G_IO_IN | G_IO_HUP | G_IO_ERR,
- };
- so->pollfds_idx = pollfds->len;
- g_array_append_val(pollfds, pfd);
- }
+ slirp->do_slowtimo |= slirp_poll_update_udb(so);
}
/*
@@ -595,29 +601,6 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
*/
}
}
-
- /*
- * Now UDP sockets.
- * Incoming packets are sent straight away, they're not buffered.
- * Incoming UDP data isn't buffered either.
- */
- for (so = slirp->udb.so_next; so != &slirp->udb;
- so = so_next) {
- int revents;
-
- so_next = so->so_next;
-
- revents = 0;
- if (so->pollfds_idx != -1) {
- revents = g_array_index(pollfds, GPollFD,
- so->pollfds_idx).revents;
- }
-
- if (so->s != -1 &&
- (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) {
- sorecvfrom(so);
- }
- }
}
if_start(slirp);
--
2.4.2
next prev parent reply other threads:[~2015-06-10 9:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 1/9] aio: Introduce aio_set_fd_handler_pri Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 2/9] iohandler: Use aio code Fam Zheng
2015-06-16 13:57 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-06-19 1:05 ` Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 3/9] main-loop: Move include of "qemu/sockets.h" to libslirp.h Fam Zheng
2015-06-16 13:58 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-06-10 8:59 ` [Qemu-devel] [PATCH 4/9] slirp: Remove dead code for "PROBE_CONN" Fam Zheng
2015-06-16 14:00 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-06-10 8:59 ` [Qemu-devel] [PATCH 5/9] slirp: Add "poll_events" to struct socket Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 6/9] slirp: Move icmp socket to iohandler Fam Zheng
2015-06-10 8:59 ` Fam Zheng [this message]
2015-06-10 8:59 ` [Qemu-devel] [PATCH 8/9] slirp: Move tcb " Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 9/9] slirp: Remove unused pollfds from the parameter list Fam Zheng
2015-06-16 14:15 ` Stefan Hajnoczi
2015-06-19 1:03 ` Fam Zheng
2015-06-16 14:16 ` [Qemu-devel] [Qemu-block] [PATCH 0/9] slirp: iohandler: Rebase onto aio Stefan Hajnoczi
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=1433926791-10580-8-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=sw@weilnetz.de \
/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).