Commit aaf10d9d2e14ceed03b75f24494fb3e8c4d15d57

Authored by Ed Swierk
Committed by Anthony Liguori
1 parent 97df1ee5

slirp: Use monotonic clock if available (v2)

Calling gettimeofday() to compute a time interval can cause problems if
the system clock jumps forwards or backwards; replace updtime() with
qemu_get_clock(rt_clock), which calls clock_gettime(CLOCK_MONOTONIC) if
it is available.

Also remove some useless macros.

Signed-off-by: Ed Swierk <eswierk@aristanetworks.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
slirp/slirp.c
... ... @@ -22,6 +22,7 @@
22 22 * THE SOFTWARE.
23 23 */
24 24 #include "qemu-common.h"
  25 +#include "qemu-timer.h"
25 26 #include "qemu-char.h"
26 27 #include "slirp.h"
27 28 #include "hw/hw.h"
... ... @@ -244,29 +245,6 @@ void slirp_cleanup(Slirp *slirp)
244 245 #define CONN_CANFRCV(so) (((so)->so_state & (SS_FCANTRCVMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
245 246 #define UPD_NFDS(x) if (nfds < (x)) nfds = (x)
246 247  
247   -/*
248   - * curtime kept to an accuracy of 1ms
249   - */
250   -#ifdef _WIN32
251   -static void updtime(void)
252   -{
253   - struct _timeb tb;
254   -
255   - _ftime(&tb);
256   -
257   - curtime = tb.time * 1000 + tb.millitm;
258   -}
259   -#else
260   -static void updtime(void)
261   -{
262   - struct timeval tv;
263   -
264   - gettimeofday(&tv, NULL);
265   -
266   - curtime = tv.tv_sec * 1000 + tv.tv_usec / 1000;
267   -}
268   -#endif
269   -
270 248 void slirp_select_fill(int *pnfds,
271 249 fd_set *readfds, fd_set *writefds, fd_set *xfds)
272 250 {
... ... @@ -405,8 +383,7 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,
405 383 global_writefds = writefds;
406 384 global_xfds = xfds;
407 385  
408   - /* Update time */
409   - updtime();
  386 + curtime = qemu_get_clock(rt_clock);
410 387  
411 388 TAILQ_FOREACH(slirp, &slirp_instances, entry) {
412 389 /*
... ...
slirp/slirp.h
... ... @@ -108,10 +108,6 @@ typedef unsigned char u_int8_t;
108 108 #include <arpa/inet.h>
109 109 #endif
110 110  
111   -#ifdef GETTIMEOFDAY_ONE_ARG
112   -#define gettimeofday(x, y) gettimeofday(x)
113   -#endif
114   -
115 111 /* Systems lacking strdup() definition in <string.h>. */
116 112 #if defined(ultrix)
117 113 char *strdup(const char *);
... ...
slirp/slirp_config.h
... ... @@ -187,9 +187,6 @@
187 187 #define NO_UNIX_SOCKETS
188 188 #endif
189 189  
190   -/* Define if gettimeofday only takes one argument */
191   -#undef GETTIMEOFDAY_ONE_ARG
192   -
193 190 /* Define if you have revoke() */
194 191 #undef HAVE_REVOKE
195 192  
... ...