]> granicus.if.org Git - mutt/commitdiff
Convert raw_socket_poll() to use gettimeofday().
authorKevin McCarthy <kevin@8t8.us>
Fri, 28 Jul 2017 17:54:51 +0000 (10:54 -0700)
committerKevin McCarthy <kevin@8t8.us>
Fri, 28 Jul 2017 17:54:51 +0000 (10:54 -0700)
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.

configure.ac
mutt_socket.c

index ef408ca90555a57e707c81d84ec0990dea32920e..a9c3206899e18408195c5879f42482467968c8f8 100644 (file)
@@ -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])
index bd585c759d7f95551678cb6d41c702cc6d004696..16e52dce0919bec52705dcdbc2624a1fa4bfce42 100644 (file)
@@ -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;
   }
 }