| 17 |
|
|
| 18 |
#include "io.h" |
#include "io.h" |
| 19 |
#include "common.h" |
#include "common.h" |
| 20 |
|
#include "tcplib.h" |
| 21 |
#include <stdio.h> |
#include <stdio.h> |
| 22 |
#include <stdarg.h> |
#include <stdarg.h> |
| 23 |
#include <time.h> |
#include <time.h> |
| 66 |
int out = KEY_NULL, loop = 1, in_esc = 0, in_ascii = 0, in_control = 0, i = |
int out = KEY_NULL, loop = 1, in_esc = 0, in_ascii = 0, in_control = 0, i = |
| 67 |
0, j, result; |
0, j, result; |
| 68 |
static int len = 0, pos = 0; |
static int len = 0, pos = 0; |
| 69 |
fd_set inputs, testfds; |
fd_set testfds; |
| 70 |
struct timeval timeout; |
struct timeval timeout; |
| 71 |
|
|
| 72 |
|
//Stop on system exit |
| 73 |
|
if (SYS_exit) |
| 74 |
|
return KEY_NULL; |
| 75 |
|
|
| 76 |
if (pos >= len) |
if (pos >= len) |
| 77 |
{ |
{ |
| 78 |
pos = 0; |
pos = 0; |
| 79 |
len = 0; |
len = 0; |
| 80 |
|
|
| 81 |
FD_ZERO (&inputs); |
FD_ZERO (&testfds); |
| 82 |
FD_SET (0, &inputs); |
FD_SET (0, &testfds); |
| 83 |
|
|
|
testfds = inputs; |
|
| 84 |
timeout.tv_sec = 1; |
timeout.tv_sec = 1; |
| 85 |
timeout.tv_usec = 0; |
timeout.tv_usec = 0; |
| 86 |
|
|
| 87 |
result = select (FD_SETSIZE, &testfds, (fd_set *) NULL, |
result = SignalSafeSelect (FD_SETSIZE, &testfds, (fd_set *) NULL, |
| 88 |
(fd_set *) NULL, &timeout); |
(fd_set *) NULL, &timeout); |
| 89 |
|
|
| 90 |
switch (result) |
if (result == 0) |
| 91 |
|
{ |
| 92 |
|
return KEY_TIMEOUT; |
| 93 |
|
} |
| 94 |
|
if (result < 0) |
| 95 |
|
{ |
| 96 |
|
log_error ("select() error (%d) !\n", result); |
| 97 |
|
return KEY_NULL; |
| 98 |
|
} |
| 99 |
|
if (result > 0) |
| 100 |
{ |
{ |
|
case 0: |
|
|
out = KEY_TIMEOUT; |
|
|
break; |
|
|
case -1: |
|
|
log_error ("select() error!\n"); |
|
|
break; |
|
|
default: |
|
| 101 |
if (FD_ISSET (0, &testfds)) |
if (FD_ISSET (0, &testfds)) |
| 102 |
{ |
{ |
| 103 |
len = read (0, buf, 255); |
len = read (0, buf, 255); |
| 104 |
} |
} |
|
break; |
|
| 105 |
} |
} |
| 106 |
|
|
| 107 |
//For debug |
//For debug |
| 234 |
{ |
{ |
| 235 |
ch = igetch (); |
ch = igetch (); |
| 236 |
} |
} |
| 237 |
while ((ch == KEY_TIMEOUT) && (time (0) - t_begin < sec)); |
while ((ch == KEY_TIMEOUT || ch == 0xa) && (time (0) - t_begin < sec)); |
| 238 |
|
|
| 239 |
return ch; |
return ch; |
| 240 |
} |
} |