]> granicus.if.org Git - neomutt/commitdiff
Add new timeout functions to work with inotify monitors.
authorKevin McCarthy <kevin@8t8.us>
Mon, 4 Jun 2018 01:34:21 +0000 (18:34 -0700)
committerRichard Russon <rich@flatcap.org>
Mon, 3 Sep 2018 01:04:32 +0000 (02:04 +0100)
The ncurses timeout() function doesn't affect the new poll inside
mutt_monitor_poll().  This meant that $imap_keepalive and $timeout
were not being respected when the monitor was used.

Create mutt_getch_timeout(), which delegates to timeout() and sets a
timeout value mutt_monitor_poll() uses too.

curs_lib.c
curs_lib.h
keymap.c
monitor.c
monitor.h

index fac01c5d205fa839a43ecacc71bdefac690b1fe4..63ab60f38433fe68dd638b36607500c670bb0b65 100644 (file)
@@ -119,6 +119,19 @@ void mutt_need_hard_redraw(void)
   mutt_menu_set_current_redraw_full();
 }
 
+/* delay is just like for timeout() or poll():
+ *   the number of milliseconds mutt_getch() should block for input.
+ *   delay == 0 means mutt_getch() is non-blocking.
+ *   delay < 0 means mutt_getch is blocking.
+ */
+void mutt_getch_timeout(int delay)
+{
+  timeout(delay);
+#ifdef USE_INOTIFY
+  mutt_monitor_set_poll_timeout(delay);
+#endif
+}
+
 /**
  * mutt_getch - Read a character from the input buffer
  * @retval obj Event to process
@@ -355,9 +368,9 @@ int mutt_yesorno(const char *msg, int def)
 
     mutt_refresh();
     /* SigWinch is not processed unless timeout is set */
-    timeout(30 * 1000);
+    mutt_getch_timeout(30 * 1000);
     ch = mutt_getch();
-    timeout(-1);
+    mutt_getch_timeout(-1);
     if (ch.ch == -2)
       continue;
     if (CI_is_return(ch.ch))
@@ -424,7 +437,7 @@ void mutt_query_exit(void)
   mutt_flushinp();
   curs_set(1);
   if (Timeout)
-    timeout(-1); /* restore blocking operation */
+    mutt_getch_timeout(-1); /* restore blocking operation */
   if (mutt_yesorno(_("Exit NeoMutt?"), MUTT_YES) == MUTT_YES)
   {
     mutt_exit(1);
@@ -789,9 +802,9 @@ int mutt_multi_choice(const char *prompt, const char *letters)
 
     mutt_refresh();
     /* SigWinch is not processed unless timeout is set */
-    timeout(30 * 1000);
+    mutt_getch_timeout(30 * 1000);
     ch = mutt_getch();
-    timeout(-1);
+    mutt_getch_timeout(-1);
     if (ch.ch == -2)
       continue;
     /* (ch.ch == 0) is technically possible.  Treat the same as < 0 (abort) */
index 1e3e4ab856b7d3db4f528dda72255c6d5ce80e46..6a926f85f5ce66caf9860bd6610fc4cfc349b890 100644 (file)
@@ -54,6 +54,7 @@ void         mutt_flush_unget_to_endcond(void);
 void         mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s);
 void         mutt_format_s_tree(char *buf, size_t buflen, const char *prec, const char *s);
 struct Event mutt_getch(void);
+void         mutt_getch_timeout(int);
 int          mutt_get_field_full(const char *field, char *buf, size_t buflen, int complete, bool multiple, char ***files, int *numfiles);
 int          mutt_get_field_unbuffered(char *msg, char *buf, size_t buflen, int flags);
 int          mutt_multi_choice(const char *prompt, const char *letters);
index c9eebe28ab08cd4b6ed19eb0789355037b551454..2f207274181d42ec5e8cde5d18399fb86a2fb749 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -586,9 +586,9 @@ int km_dokey(int menu)
       {
         while (ImapKeepalive && ImapKeepalive < i)
         {
-          timeout(ImapKeepalive * 1000);
+          mutt_getch_timeout(ImapKeepalive * 1000);
           tmp = mutt_getch();
-          timeout(-1);
+          mutt_getch_timeout(-1);
           /* If a timeout was not received, or the window was resized, exit the
            * loop now.  Otherwise, continue to loop until reaching a total of
            * $timeout seconds.
@@ -606,9 +606,9 @@ int km_dokey(int menu)
     }
 #endif
 
-    timeout(i * 1000);
+    mutt_getch_timeout(i * 1000);
     tmp = mutt_getch();
-    timeout(-1);
+    mutt_getch_timeout(-1);
 
 #ifdef USE_IMAP
   gotkey:
index 22fd9d630f5e4d24707bd1d09ee0e75708f9538d..30019cd6b4069c4e4e184c76a809e65f3eef94f5 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -56,6 +56,7 @@ static struct Monitor *Monitor = NULL;
 static size_t PollFdsCount = 0;
 static size_t PollFdsLen = 0;
 static struct pollfd *PollFds;
+static int PollTimeout = -1;
 
 struct MonitorInfo
 {
@@ -213,6 +214,11 @@ static int monitor_handle_ignore(int desc)
   return new_descr;
 }
 
+void mutt_monitor_set_poll_timeout(int timeout)
+{
+  PollTimeout = timeout;
+}
+
 #define EVENT_BUFLEN MAX(4096, sizeof(struct inotify_event) + NAME_MAX + 1)
 
 /* mutt_monitor_poll: Waits for I/O ready file descriptors or signals.
@@ -236,7 +242,7 @@ int mutt_monitor_poll(void)
 
   if (INotifyFd != -1)
   {
-    fds = poll(PollFds, PollFdsLen, -1);
+    fds = poll(PollFds, PollFdsLen, PollTimeout);
 
     if (fds == -1)
     {
index 1159abe07badc9766b9fa7e9037ad7d81687ec1c..d61550b051bf1c96bb168e2ef14196d9e8b17780 100644 (file)
--- a/monitor.h
+++ b/monitor.h
@@ -29,6 +29,7 @@ struct Mailbox;
 
 int mutt_monitor_add(struct Mailbox *b);
 int mutt_monitor_remove(struct Mailbox *b);
+void mutt_monitor_set_poll_timeout(int timeout);
 int mutt_monitor_poll(void);
 
 #endif /* _MUTT_MONITOR_H */