Always timeout the poll.

Otherwise, events like the laststatus update and (more importantly) lastsave
don't get run unless there's a running entry.
This commit is contained in:
Felicity Tarnell 2014-03-07 22:03:47 +00:00
parent 0c3b7443d5
commit e8396d70ba

18
tts.c
View file

@ -467,8 +467,7 @@ struct kevent64_s evs[2], rev;
timeout.tv_sec = 0;
timeout.tv_nsec = 500000000;
if ((nev = kevent64(kq, NULL, 0, &rev, 1, 0,
running ? &timeout : NULL)) == -1) {
if ((nev = kevent64(kq, NULL, 0, &rev, 1, 0, &timeout)) == -1) {
if (doexit)
break;
if (errno == EINTR)
@ -477,9 +476,6 @@ struct kevent64_s evs[2], rev;
return 1;
}
if (nev == 0)
continue;
if (rev.filter == EVFILT_MACHPORT) {
power_handle(&rev);
continue;
@ -492,20 +488,12 @@ struct kevent64_s evs[2], rev;
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
/*
* If there's a running entry, wake up in 0.5 seconds time to update
* the display. Otherwise, we can sleep forever.
*/
if (select(STDIN_FILENO + 1, &in_set, NULL, NULL,
running ? &timeout : NULL) == -1) {
if (select(STDIN_FILENO + 1, &in_set, NULL, NULL, &timeout) == -1) {
if (doexit)
break;
if (errno == EINTR)
continue;
}
if (!FD_ISSET(STDIN_FILENO, &in_set))
continue;
#endif
while (GETCH(&c) != ERR) {
@ -529,8 +517,10 @@ struct kevent64_s evs[2], rev;
if (doexit)
break;
if (time(NULL) - laststatus >= 2)
drawstatus(WIDE(""));
if (time(NULL) - lastsave > 60)
save();
}