From: Kevin McCarthy Date: Fri, 28 Jul 2017 17:54:51 +0000 (-0700) Subject: Convert raw_socket_poll() to use gettimeofday(). X-Git-Tag: mutt-1-9-rel~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=74ec847b2445f971e9b2be4c019e4b1700f3916f;p=mutt Convert raw_socket_poll() to use gettimeofday(). As long as gettimeofday() is supported, it's better to be consistent within mutt and ensure greater portability. Change the raw_socket_poll() wait timer to count milliseconds, like the mutt_progess_update() code. Thanks to Vincent Lefèvre for his, as always, invaluable advice. --- diff --git a/configure.ac b/configure.ac index ef408ca9..a9c32068 100644 --- a/configure.ac +++ b/configure.ac @@ -643,13 +643,6 @@ if test "$need_socket" = "yes" then AC_CHECK_HEADERS([sys/select.h]) - mutt_save_LIBS="$LIBS" - LIBS= - AC_SEARCH_LIBS([clock_gettime], [rt], - MUTTLIBS="$MUTTLIBS $LIBS", - AC_MSG_ERROR([Unable to find clock_gettime function])) - LIBS="$mutt_save_LIBS" - AC_MSG_CHECKING([for socklen_t]) AC_EGREP_HEADER(socklen_t, sys/socket.h, AC_MSG_RESULT([yes]), AC_MSG_RESULT([no]) diff --git a/mutt_socket.c b/mutt_socket.c index bd585c75..16e52dce 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -435,25 +435,26 @@ int raw_socket_write (CONNECTION* conn, const char* buf, size_t count) int raw_socket_poll (CONNECTION* conn, time_t wait_secs) { fd_set rfds; - struct timeval tv; - struct timespec pre_t, post_t; - time_t sleep_secs; + unsigned long wait_millis, post_t_millis; + struct timeval tv, pre_t, post_t; int rv; if (conn->fd < 0) return -1; + wait_millis = wait_secs * 1000UL; + FOREVER { - tv.tv_sec = wait_secs; - tv.tv_usec = 0; + tv.tv_sec = wait_millis / 1000; + tv.tv_usec = (wait_millis % 1000) * 1000; FD_ZERO (&rfds); FD_SET (conn->fd, &rfds); - clock_gettime (CLOCK_MONOTONIC, &pre_t); + gettimeofday (&pre_t, NULL); rv = select (conn->fd + 1, &rfds, NULL, NULL, &tv); - clock_gettime (CLOCK_MONOTONIC, &post_t); + gettimeofday (&post_t, NULL); if (rv > 0 || (rv < 0 && errno != EINTR)) @@ -462,10 +463,11 @@ int raw_socket_poll (CONNECTION* conn, time_t wait_secs) if (SigInt) mutt_query_exit (); - sleep_secs = post_t.tv_sec - pre_t.tv_sec; - if (wait_secs <= sleep_secs) + wait_millis += (pre_t.tv_sec * 1000UL) + (pre_t.tv_usec / 1000); + post_t_millis = (post_t.tv_sec * 1000UL) + (post_t.tv_usec / 1000); + if (wait_millis <= post_t_millis) return 0; - wait_secs -= sleep_secs; + wait_millis -= post_t_millis; } }