]> granicus.if.org Git - neomutt/commitdiff
error: use sleep_time as error wait time
authorRoger Pau Monne <roger.pau@citrix.com>
Wed, 21 Mar 2018 12:29:09 +0000 (12:29 +0000)
committerRichard Russon <rich@flatcap.org>
Thu, 22 Mar 2018 15:59:11 +0000 (15:59 +0000)
Also fix the conversion from us to ns.

mutt_logging.c

index 8d4c1b579f9184311c44631df6a156529e276d36..6c568cdaa6de7cf81e3dffbf0222681a19457747 100644 (file)
@@ -45,6 +45,10 @@ char *DebugFile = NULL;  /**< Log file name */
 const int NumOfLogs = 5; /**< How many log files to rotate */
 bool LogAllowDebugSet = false;
 
+#define S_TO_NS  1000000000UL
+#define S_TO_US  1000000UL
+#define US_TO_NS 1000UL
+
 /**
  * micro_elapsed - Number of microseconds between two timevals
  * @param begin Begin time
@@ -57,13 +61,14 @@ static long micro_elapsed(const struct timeval *begin, const struct timeval *end
   if ((begin->tv_sec == 0) && (end->tv_sec != 0))
     return LONG_MAX;
 
-  return ((end->tv_sec - begin->tv_sec) * 1000000) + (end->tv_usec - begin->tv_usec);
+  return ((end->tv_sec - begin->tv_sec) * S_TO_US) +
+         (end->tv_usec - begin->tv_usec);
 }
 
 /**
  * error_pause - Wait for an error message to be read
  *
- * If a second hasn't elapsed since LastError, then wait.
+ * If '$sleep_time' seconds hasn't elapsed since LastError, then wait
  */
 static void error_pause(void)
 {
@@ -75,12 +80,17 @@ static void error_pause(void)
     return;
   }
 
+  unsigned long sleep = SleepTime * S_TO_NS;
   long micro = micro_elapsed(&LastError, &now);
-  if (micro >= 1000000)
+  if ((micro * US_TO_NS) >= sleep)
     return;
 
-  struct timespec wait = { 0 };
-  wait.tv_nsec = 1000000000 - (micro * 10);
+  sleep -= (micro * US_TO_NS);
+
+  struct timespec wait = {
+    .tv_sec = (sleep / S_TO_NS),
+    .tv_nsec = (sleep % S_TO_NS),
+  };
 
   mutt_refresh();
   nanosleep(&wait, NULL);