/[LeafOK_CVS]/lbbs/src/io.c
ViewVC logotype

Diff of /lbbs/src/io.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.21 by sysadm, Fri May 9 11:21:11 2025 UTC Revision 1.25 by sysadm, Sat May 10 15:23:42 2025 UTC
# Line 17  Line 17 
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)
# Line 58  int iflush() Line 59  int iflush()
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;
# Line 86  int igetch(int clear_buf) Line 87  int igetch(int clear_buf)
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    
# Line 107  int igetch(int clear_buf) Line 108  int igetch(int clear_buf)
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                  }                  }
# Line 123  int igetch(int clear_buf) Line 124  int igetch(int clear_buf)
124    
125                  if (c == '\0')                  if (c == '\0')
126                  {                  {
127                          out = c;                          return KEY_NULL;
                         break;  
128                  }                  }
129    
130                  if (c == KEY_CONTROL)                  if (c == KEY_CONTROL)
# Line 240  int igetch_t(long int sec) Line 240  int igetch_t(long int sec)
240          do          do
241          {          {
242                  ch = igetch(0);                  ch = igetch(0);
243          } while ((ch == KEY_TIMEOUT || ch == 0xa) && (time(0) - t_begin < sec));          } while (!SYS_server_exit && ch == KEY_TIMEOUT && (time(0) - t_begin < sec));
244    
245          return ch;          return ch;
246  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1