From 938963c1d1c6a9b929d28a90030332d4f397ca61 Mon Sep 17 00:00:00 2001 From: defanor Date: Tue, 2 May 2023 13:05:26 +0300 Subject: Use timespec and monotonic clock for timers --- emacs/xml_interface.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'emacs') diff --git a/emacs/xml_interface.c b/emacs/xml_interface.c index 7db2c63..2f4ebba 100644 --- a/emacs/xml_interface.c +++ b/emacs/xml_interface.c @@ -329,8 +329,10 @@ int main (int argc, char **argv) { fd_set read_fds, write_fds; int nfds; - struct timeval tv; - struct timeval *mtv; + struct timespec tv; + struct timespec *mtv; + struct timeval tv_ms; + struct timeval *mtv_ms; int n = 0; do { @@ -367,7 +369,13 @@ int main (int argc, char **argv) { FD_ZERO(&read_fds); FD_ZERO(&write_fds); nfds = rexmpp_fds(&s, &read_fds, &write_fds); - mtv = rexmpp_timeout(&s, NULL, (struct timeval*)&tv); + mtv = rexmpp_timeout(&s, NULL, &tv); + mtv_ms = NULL; + if (mtv != NULL) { + tv_ms.tv_sec = mtv->tv_sec; + tv_ms.tv_usec = mtv->tv_nsec / 1000; + mtv_ms = &tv_ms; + } /* Add other file descriptors we are interested in, particularly stdin for user input. */ @@ -375,7 +383,7 @@ int main (int argc, char **argv) { /* Run select(2) with all those file descriptors and timeouts, waiting for either user input or some rexmpp event to occur. */ - n = select(nfds, &read_fds, &write_fds, NULL, mtv); + n = select(nfds, &read_fds, &write_fds, NULL, mtv_ms); if (n == -1) { printf("select error: %s\n", strerror(errno)); break; -- cgit v1.2.3