diff options
author | Liu Ping Fan <qemulist@gmail.com> | 2013-08-25 10:01:21 +0800 |
---|---|---|
committer | Jan Kiszka <jan.kiszka@siemens.com> | 2013-09-17 12:26:05 +0200 |
commit | 0a165d09ccd3b1686bd5d29d1a0a58926776b993 (patch) | |
tree | 3fe565bce03a3df2d3eeccaab7153176108942b4 | |
parent | f8eebce425fc41f277e083e2e96b08e693b12de5 (diff) | |
download | slirp-0a165d09ccd3b1686bd5d29d1a0a58926776b993.zip slirp-0a165d09ccd3b1686bd5d29d1a0a58926776b993.tar.gz slirp-0a165d09ccd3b1686bd5d29d1a0a58926776b993.tar.bz2 |
slirp: set mainloop timeout with more precise value
If slirp needs to emulate tcp timeout, then the timeout value
for mainloop should be more precise, which is determined by
slirp's fasttimo or slowtimo. Achieve this by swap the logic
sequence of slirp_pollfds_fill and slirp_update_timeout.
Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
-rw-r--r-- | libslirp.h | 3 | ||||
-rw-r--r-- | slirp.c | 28 |
2 files changed, 25 insertions, 6 deletions
@@ -16,8 +16,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork, void *opaque); void slirp_cleanup(Slirp *slirp); -void slirp_update_timeout(uint32_t *timeout); -void slirp_pollfds_fill(GArray *pollfds); +void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout); void slirp_pollfds_poll(GArray *pollfds, int select_error); @@ -263,14 +263,33 @@ void slirp_cleanup(Slirp *slirp) #define CONN_CANFRCV(so) \ (((so)->so_state & (SS_FCANTRCVMORE | SS_ISFCONNECTED)) == SS_ISFCONNECTED) -void slirp_update_timeout(uint32_t *timeout) +static void slirp_update_timeout(uint32_t *timeout) { - if (!QTAILQ_EMPTY(&slirp_instances)) { - *timeout = MIN(TIMEOUT_DEFAULT, *timeout); + Slirp *slirp; + uint32_t t; + + if (*timeout <= TIMEOUT_FAST) { + return; + } + *timeout = MIN(1000, *timeout); + t = *timeout; + + /* If we have tcp timeout with slirp, then we will fill @timeout with + * more precise value. + */ + QTAILQ_FOREACH (slirp, &slirp_instances, entry) { + if (slirp->time_fasttimo) { + *timeout = TIMEOUT_FAST; + return; + } + if (slirp->do_slowtimo) { + t = MIN(TIMEOUT_SLOW, t); + } } + *timeout = t; } -void slirp_pollfds_fill(GArray *pollfds) +void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout) { Slirp *slirp; struct socket *so, *so_next; @@ -437,6 +456,7 @@ void slirp_pollfds_fill(GArray *pollfds) } } } + slirp_update_timeout(timeout); } void slirp_pollfds_poll(GArray *pollfds, int select_error) |