Skip to content

Commit

Permalink
slirp: set mainloop timeout with more precise value
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
pfliu authored and jan-kiszka committed Sep 17, 2013
1 parent 9b0ca6c commit a42e9c4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
3 changes: 1 addition & 2 deletions main-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ int main_loop_wait(int nonblocking)
g_array_set_size(gpollfds, 0); /* reset for new iteration */
/* XXX: separate device handlers from system ones */
#ifdef CONFIG_SLIRP
slirp_update_timeout(&timeout);
slirp_pollfds_fill(gpollfds);
slirp_pollfds_fill(gpollfds, &timeout);
#endif
qemu_iohandler_fill(gpollfds);

Expand Down
3 changes: 1 addition & 2 deletions slirp/libslirp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
28 changes: 24 additions & 4 deletions slirp/slirp.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,33 @@ void slirp_cleanup(Slirp *slirp)
#define CONN_CANFSEND(so) (((so)->so_state & (SS_FCANTSENDMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
#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;
Expand Down Expand Up @@ -439,6 +458,7 @@ void slirp_pollfds_fill(GArray *pollfds)
}
}
}
slirp_update_timeout(timeout);
}

void slirp_pollfds_poll(GArray *pollfds, int select_error)
Expand Down
6 changes: 1 addition & 5 deletions stubs/slirp.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#include "qemu-common.h"
#include "slirp/slirp.h"

void slirp_update_timeout(uint32_t *timeout)
{
}

void slirp_pollfds_fill(GArray *pollfds)
void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
{
}

Expand Down

0 comments on commit a42e9c4

Please sign in to comment.