From 80e36aa669274637bcd5956fbf4020dba1d4739c Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sat, 9 Feb 2013 01:51:36 -0800 Subject: Strictify timers --- src/common/socket.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/common/socket.cpp') diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 50c08a0..ac5a17d 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -332,7 +332,7 @@ void WFIFOSET(int fd, size_t len) FPRINTF(stderr, "socket: %d wdata lost !!\n", fd), abort(); } -void do_sendrecv(uint32_t next) +void do_sendrecv(interval_t next_ms) { fd_set rfd = readfds, wfd; FD_ZERO(&wfd); @@ -342,8 +342,12 @@ void do_sendrecv(uint32_t next) FD_SET(i, &wfd); } struct timeval timeout; - timeout.tv_sec = next / 1000; - timeout.tv_usec = next % 1000 * 1000; + { + std::chrono::seconds next_s = std::chrono::duration_cast(next_ms); + std::chrono::microseconds next_us = next_ms - next_s; + timeout.tv_sec = next_s.count(); + timeout.tv_usec = next_us.count(); + } if (select(fd_max, &rfd, &wfd, NULL, &timeout) <= 0) return; for (int i = 0; i < fd_max; i++) -- cgit v1.2.3-60-g2f50