| 68 |
|
|
| 69 |
unsigned char tmp[LINE_BUFFER_LEN]; |
unsigned char tmp[LINE_BUFFER_LEN]; |
| 70 |
int ret; |
int ret; |
| 71 |
int out = KEY_NULL; |
int out = '\0'; |
| 72 |
int in_esc = 0; |
int in_esc = 0; |
| 73 |
int in_ascii = 0; |
int in_ascii = 0; |
| 74 |
int in_control = 0; |
int in_control = 0; |
| 75 |
int i = 0; |
int i = 0; |
| 76 |
|
int flags; |
| 77 |
|
|
| 78 |
if (clear_buf) |
if (clear_buf) |
| 79 |
{ |
{ |
| 80 |
pos = 0; |
pos = 0; |
| 81 |
len = 0; |
len = 0; |
| 82 |
|
|
| 83 |
return 0; |
return '\0'; |
| 84 |
} |
} |
| 85 |
|
|
| 86 |
while (!SYS_server_exit && pos >= len) |
while (!SYS_server_exit && pos >= len) |
| 91 |
timeout.tv_sec = 0; |
timeout.tv_sec = 0; |
| 92 |
timeout.tv_usec = 100 * 1000; // 0.1 second |
timeout.tv_usec = 100 * 1000; // 0.1 second |
| 93 |
|
|
| 94 |
ret = select(FD_SETSIZE, &testfds, NULL, NULL, &timeout); |
ret = select(STDIN_FILENO + 1, &testfds, NULL, NULL, &timeout); |
| 95 |
|
|
| 96 |
if (ret < 0) |
if (ret < 0) |
| 97 |
{ |
{ |
| 98 |
if (errno != EINTR) |
if (errno != EINTR) |
| 99 |
{ |
{ |
| 100 |
log_error("Select error in igetch: !\n", errno); |
log_error("select() error (%d) !\n", errno); |
| 101 |
return KEY_NULL; |
return KEY_NULL; |
| 102 |
} |
} |
| 103 |
continue; |
continue; |
| 109 |
|
|
| 110 |
if (FD_ISSET(STDIN_FILENO, &testfds)) |
if (FD_ISSET(STDIN_FILENO, &testfds)) |
| 111 |
{ |
{ |
| 112 |
|
flags = fcntl(STDIN_FILENO, F_GETFL, 0); |
| 113 |
|
fcntl(socket_server, F_SETFL, flags | O_NONBLOCK); |
| 114 |
|
|
| 115 |
len = read(STDIN_FILENO, buf, sizeof(buf)); |
len = read(STDIN_FILENO, buf, sizeof(buf)); |
| 116 |
|
if (len < 0) |
| 117 |
|
{ |
| 118 |
|
if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) |
| 119 |
|
{ |
| 120 |
|
log_error("read(STDIN) error (%d)\n", errno); |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
else if (len == 0) |
| 124 |
|
{ |
| 125 |
|
out = KEY_NULL; // broken pipe |
| 126 |
|
} |
| 127 |
|
|
| 128 |
pos = 0; |
pos = 0; |
| 129 |
|
|
| 130 |
|
fcntl(STDIN_FILENO, F_SETFL, flags); |
| 131 |
|
|
| 132 |
break; |
break; |
| 133 |
} |
} |
| 134 |
|
|
| 141 |
{ |
{ |
| 142 |
unsigned char c = buf[pos++]; |
unsigned char c = buf[pos++]; |
| 143 |
|
|
|
if (c == '\0') |
|
|
{ |
|
|
return KEY_NULL; |
|
|
} |
|
|
|
|
| 144 |
if (c == KEY_CONTROL) |
if (c == KEY_CONTROL) |
| 145 |
{ |
{ |
| 146 |
if (in_control == 0) |
if (in_control == 0) |