From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDPeh-0006SY-8y for qemu-devel@nongnu.org; Sat, 24 Aug 2013 22:02:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VDPeY-0003FS-QG for qemu-devel@nongnu.org; Sat, 24 Aug 2013 22:02:15 -0400 Received: from mail-pb0-x229.google.com ([2607:f8b0:400e:c01::229]:53937) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDPeY-0003FO-KX for qemu-devel@nongnu.org; Sat, 24 Aug 2013 22:02:06 -0400 Received: by mail-pb0-f41.google.com with SMTP id rp2so2113948pbb.0 for ; Sat, 24 Aug 2013 19:02:05 -0700 (PDT) From: Liu Ping Fan Date: Sun, 25 Aug 2013 10:01:20 +0800 Message-Id: <1377396081-12417-3-git-send-email-pingfank@linux.vnet.ibm.com> In-Reply-To: <1377396081-12417-1-git-send-email-pingfank@linux.vnet.ibm.com> References: <1377396081-12417-1-git-send-email-pingfank@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v4 2/3] slirp: define timeout as macro List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Jan Kiszka , Stefan Hajnoczi , Paolo Bonzini Signed-off-by: Liu Ping Fan --- slirp/slirp.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/slirp/slirp.c b/slirp/slirp.c index b71c617..c47af8f 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -47,6 +47,11 @@ static QTAILQ_HEAD(slirp_instances, Slirp) slirp_instances = static struct in_addr dns_addr; static u_int dns_addr_time; +#define TIMEOUT_FAST 2 /* milliseconds */ +#define TIMEOUT_SLOW 499 /* milliseconds */ +/* for the aging of certain requests like DNS */ +#define TIMEOUT_DEFAULT 1000 /* milliseconds */ + #ifdef _WIN32 int get_dns_addr(struct in_addr *pdns_addr) @@ -57,7 +62,7 @@ int get_dns_addr(struct in_addr *pdns_addr) IP_ADDR_STRING *pIPAddr; struct in_addr tmp_addr; - if (dns_addr.s_addr != 0 && (curtime - dns_addr_time) < 1000) { + if (dns_addr.s_addr != 0 && (curtime - dns_addr_time) < TIMEOUT_DEFAULT) { *pdns_addr = dns_addr; return 0; } @@ -113,7 +118,7 @@ int get_dns_addr(struct in_addr *pdns_addr) if (dns_addr.s_addr != 0) { struct stat old_stat; - if ((curtime - dns_addr_time) < 1000) { + if ((curtime - dns_addr_time) < TIMEOUT_DEFAULT) { *pdns_addr = dns_addr; return 0; } @@ -260,7 +265,7 @@ void slirp_cleanup(Slirp *slirp) void slirp_update_timeout(uint32_t *timeout) { if (!QTAILQ_EMPTY(&slirp_instances)) { - *timeout = MIN(1000, *timeout); + *timeout = MIN(TIMEOUT_DEFAULT, *timeout); } } @@ -452,11 +457,13 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error) /* * See if anything has timed out */ - if (slirp->time_fasttimo && ((curtime - slirp->time_fasttimo) >= 2)) { + if (slirp->time_fasttimo && + ((curtime - slirp->time_fasttimo) >= TIMEOUT_FAST)) { tcp_fasttimo(slirp); slirp->time_fasttimo = 0; } - if (slirp->do_slowtimo && ((curtime - slirp->last_slowtimo) >= 499)) { + if (slirp->do_slowtimo && + ((curtime - slirp->last_slowtimo) >= TIMEOUT_SLOW)) { ip_slowtimo(slirp); tcp_slowtimo(slirp); slirp->last_slowtimo = curtime; -- 1.8.1.4