Commit 3d2cef4a authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

Add new timeout functions to work with inotify monitors.

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.
parent 5ada2f51
Pipeline #23116253 passed with stages
in 19 minutes and 6 seconds
......@@ -114,6 +114,19 @@ void mutt_need_hard_redraw (void)
mutt_set_current_menu_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
}
event_t mutt_getch (void)
{
int ch;
......@@ -322,9 +335,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))
......@@ -400,7 +413,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 Mutt?"), MUTT_YES) == MUTT_YES)
{
endwin ();
......@@ -1095,9 +1108,9 @@ int mutt_multi_choice (char *prompt, 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) */
......
......@@ -446,9 +446,9 @@ int km_dokey (int menu)
else
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.
......@@ -465,9 +465,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:
......
......@@ -50,6 +50,7 @@ static MONITOR *Monitor = NULL;
static size_t PollFdsCount = 0;
static size_t PollFdsLen = 0;
static struct pollfd *PollFds;
static int PollTimeout = -1;
typedef struct monitorinfo_t
{
......@@ -202,6 +203,11 @@ static int monitor_handle_ignore (int descr)
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.
......@@ -226,7 +232,7 @@ int mutt_monitor_poll ()
if (INotifyFd != -1)
{
fds = poll (PollFds, PollFdsLen, -1);
fds = poll (PollFds, PollFdsLen, PollTimeout);
if (fds == -1)
{
......
......@@ -25,6 +25,7 @@ WHERE int MonitorFilesChanged INITVAL (0);
int mutt_monitor_add (BUFFY *b);
int mutt_monitor_remove (BUFFY *b);
#endif
void mutt_monitor_set_poll_timeout (int timeout);
int mutt_monitor_poll ();
#endif /* MONITOR_H */
......@@ -88,6 +88,7 @@ void mutt_curs_set (int);
event_t mutt_getch (void);
void mutt_getch_timeout (int);
void mutt_endwin (const char *);
void mutt_flushinp (void);
void mutt_refresh (void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment