From 9aa28c10b8ca761cfc005ed0a6bd622c7f83c1f4 Mon Sep 17 00:00:00 2001 From: liuguangzhao Date: Sun, 8 Jun 2014 14:08:52 +0000 Subject: [PATCH] fix nTox cmdline input slow problem. --- testing/nTox.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index 7df35386..95f377ce 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -36,6 +36,7 @@ #include #endif +#include #include "nTox.h" #include "misc_tools.c" @@ -1166,6 +1167,30 @@ void write_file(Tox *m, int friendnumber, uint8_t filenumber, uint8_t *data, uin fclose(pFile); } +char timeout_getch(Tox *m) +{ + char c; + int slpval = tox_do_interval(m); + + fd_set fds; + FD_ZERO(&fds); + FD_SET(0, &fds); + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = slpval * 1000; + + c = ERR; + int n = select(1, &fds, NULL, NULL, &tv); + if (n < 0) { + new_lines("select error: maybe interupted"); + } else if (n == 0) { + } else { + c = getch(); + } + + return c; +} + int main(int argc, char *argv[]) { /* minimalistic locale support (i.e. when printing dates) */ @@ -1274,13 +1299,12 @@ int main(int argc, char *argv[]) } - c_sleep(tox_do_interval(m)); send_filesenders(m); tox_do(m); do_refresh(); - c = getch(); + c = timeout_getch(m); if (c == ERR || c == 27) continue;