--- lbbs/src/io.c 2005/03/21 17:08:21 1.8 +++ lbbs/src/io.c 2005/03/22 08:19:11 1.9 @@ -19,6 +19,9 @@ #include "common.h" #include #include +#include +#include +#include #include int @@ -60,15 +63,41 @@ igetch () static char buf[256]; unsigned char c, tmp[256]; int out = KEY_NULL, loop = 1, in_esc = 0, in_ascii = 0, in_control = 0, i = - 0, j; + 0, j, result; static int len = 0, pos = 0; + fd_set inputs, testfds; + struct timeval timeout; if (pos >= len) { pos = 0; + len = 0; - //len = s_receive (socket_client, buf, 255, ""); - len = read (0, buf, 255); + FD_ZERO (&inputs); + FD_SET (0, &inputs); + + testfds = inputs; + timeout.tv_sec = 1; + timeout.tv_usec = 0; + + result = select (FD_SETSIZE, &testfds, (fd_set *) NULL, + (fd_set *) NULL, &timeout); + + switch (result) + { + case 0: + out = KEY_TIMEOUT; + break; + case -1: + log_error ("select() error!\n"); + break; + default: + if (FD_ISSET (0, &testfds)) + { + len = read (0, buf, 255); + } + break; + } //For debug //for (j = 0; j < len; j++) @@ -191,6 +220,19 @@ igetch () } int +igetch_t (long int sec) +{ + int ch; + time_t t_begin = time(0); + + do { + ch = igetch (); + } while ((ch == KEY_TIMEOUT) && (time(0) - t_begin < sec)); + + return ch; +} + +int ikbhit () { int len;