clean-up (pipe handling)
This commit is contained in:
parent
93119054fa
commit
cf211d64a5
1 changed files with 14 additions and 11 deletions
|
@ -19,16 +19,16 @@
|
||||||
console_posix::console_posix(std::atomic_uint32_t *const stop_event): console(stop_event)
|
console_posix::console_posix(std::atomic_uint32_t *const stop_event): console(stop_event)
|
||||||
{
|
{
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
if (tcgetattr(STDIN_FILENO, &org_tty_opts) == -1 && errno != ENOTTY)
|
if (isatty(STDIN_FILENO)) {
|
||||||
|
if (tcgetattr(STDIN_FILENO, &org_tty_opts) == -1)
|
||||||
error_exit(true, "console_posix: tcgetattr failed");
|
error_exit(true, "console_posix: tcgetattr failed");
|
||||||
|
|
||||||
struct termios tty_opts_raw { };
|
struct termios tty_opts_raw { };
|
||||||
cfmakeraw(&tty_opts_raw);
|
cfmakeraw(&tty_opts_raw);
|
||||||
|
|
||||||
if (tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw) == -1 && errno != ENOTTY)
|
if (tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw) == -1)
|
||||||
error_exit(true, "console_posix: tcsetattr failed");
|
error_exit(true, "console_posix: tcsetattr failed");
|
||||||
|
}
|
||||||
setvbuf(stdin, nullptr, _IONBF, 0);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ console_posix::~console_posix()
|
||||||
stop_thread();
|
stop_thread();
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
if (tcsetattr(STDIN_FILENO, TCSANOW, &org_tty_opts) == -1 && errno != ENOTTY)
|
if (isatty(STDIN_FILENO) && tcsetattr(STDIN_FILENO, TCSANOW, &org_tty_opts) == -1)
|
||||||
error_exit(true, "~console_posix: tcsetattr failed");
|
error_exit(true, "~console_posix: tcsetattr failed");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,11 @@ int console_posix::wait_for_char_ll(const short timeout)
|
||||||
#else
|
#else
|
||||||
struct pollfd fds[] = { { STDIN_FILENO, POLLIN, 0 } };
|
struct pollfd fds[] = { { STDIN_FILENO, POLLIN, 0 } };
|
||||||
|
|
||||||
if (poll(fds, 1, timeout) == 1 && fds[0].revents)
|
if (poll(fds, 1, timeout) == 1 && fds[0].revents) {
|
||||||
return getchar();
|
char buffer = 0;
|
||||||
|
read(STDIN_FILENO, &buffer, 1);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue