From a0fc195112d6455403e2fcee9c31119a1f3e6d9a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 9 Dec 2017 09:41:37 -0500 Subject: terminal-unix: switch back to poll(3) This leverages the new polldev shim which lets us "poll" device files on macOS with select and use the genuine article on other platforms. --- osdep/terminal-unix.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index c9f3553ff0..0eca44372e 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -25,9 +25,7 @@ #include #include #include -#include #include -#include #include #include @@ -35,6 +33,7 @@ #include "osdep/io.h" #include "osdep/threads.h" +#include "osdep/polldev.h" #include "common/common.h" #include "misc/bstr.h" @@ -387,22 +386,17 @@ static void *terminal_thread(void *ptr) { mpthread_set_name("terminal"); bool stdin_ok = read_terminal; // if false, we still wait for SIGTERM - fd_set readfds; - int max = death_pipe[0] > tty_in ? death_pipe[0] : tty_in; while (1) { - FD_ZERO(&readfds); - FD_SET(death_pipe[0], &readfds); - FD_SET(tty_in, &readfds); getch2_poll(); - int s = select(max + 1, &readfds, NULL, NULL, NULL); - if (s == -1) { + struct pollfd fds[2] = { + { .events = POLLIN, .fd = death_pipe[0] }, + { .events = POLLIN, .fd = tty_in } + }; + polldev(fds, stdin_ok ? 2 : 1, -1); + if (fds[0].revents) break; - } else if (s != 0) { - if (FD_ISSET(death_pipe[0], &readfds)) - break; - if (stdin_ok && FD_ISSET(tty_in, &readfds)) - stdin_ok = getch2(input_ctx); - } + if (fds[1].revents) + getch2(input_ctx); } char c; bool quit = read(death_pipe[0], &c, 1) == 1 && c == 1; -- cgit v1.2.3