| 17 |
#include "io.h" |
#include "io.h" |
| 18 |
#include "log.h" |
#include "log.h" |
| 19 |
#include "common.h" |
#include "common.h" |
| 20 |
#include "tcplib.h" |
#include <errno.h> |
| 21 |
#include <stdio.h> |
#include <stdio.h> |
| 22 |
#include <stdarg.h> |
#include <stdarg.h> |
| 23 |
#include <time.h> |
#include <time.h> |
| 24 |
#include <fcntl.h> |
#include <fcntl.h> |
| 25 |
#include <unistd.h> |
#include <unistd.h> |
| 26 |
|
#include <sys/select.h> |
| 27 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
| 28 |
|
|
| 29 |
int outc(char c) |
int outc(char c) |
| 59 |
int igetch(int clear_buf) |
int igetch(int clear_buf) |
| 60 |
{ |
{ |
| 61 |
// static input buffer |
// static input buffer |
| 62 |
static unsigned char buf[256]; |
static unsigned char buf[LINE_BUFFER_LEN]; |
| 63 |
static ssize_t len = 0; |
static ssize_t len = 0; |
| 64 |
static int pos = 0; |
static int pos = 0; |
| 65 |
|
|
| 66 |
fd_set testfds; |
fd_set testfds; |
| 67 |
struct timeval timeout; |
struct timeval timeout; |
| 68 |
|
|
| 69 |
unsigned char tmp[256]; |
unsigned char tmp[LINE_BUFFER_LEN]; |
| 70 |
int ret; |
int ret; |
| 71 |
int out = KEY_NULL; |
int out = KEY_NULL; |
| 72 |
int in_esc = 0; |
int in_esc = 0; |
| 87 |
FD_ZERO(&testfds); |
FD_ZERO(&testfds); |
| 88 |
FD_SET(STDIN_FILENO, &testfds); |
FD_SET(STDIN_FILENO, &testfds); |
| 89 |
|
|
| 90 |
timeout.tv_sec = 1; |
timeout.tv_sec = 0; |
| 91 |
timeout.tv_usec = 0; |
timeout.tv_usec = 100 * 1000; // 0.1 second |
| 92 |
|
|
| 93 |
ret = select(FD_SETSIZE, &testfds, NULL, NULL, &timeout); |
ret = select(FD_SETSIZE, &testfds, NULL, NULL, &timeout); |
| 94 |
|
|
| 108 |
|
|
| 109 |
if (FD_ISSET(STDIN_FILENO, &testfds)) |
if (FD_ISSET(STDIN_FILENO, &testfds)) |
| 110 |
{ |
{ |
| 111 |
len = read(STDIN_FILENO, buf, 255); |
len = read(STDIN_FILENO, buf, sizeof(buf)); |
| 112 |
pos = 0; |
pos = 0; |
| 113 |
break; |
break; |
| 114 |
} |
} |