/[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.26 by sysadm, Sun May 11 04:09:08 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;
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          {          {
# Line 86  int igetch(int clear_buf) Line 88  int igetch(int clear_buf)
88                  FD_ZERO(&testfds);                  FD_ZERO(&testfds);
89                  FD_SET(STDIN_FILENO, &testfds);                  FD_SET(STDIN_FILENO, &testfds);
90    
91                  timeout.tv_sec = 1;                  timeout.tv_sec = 0;
92                  timeout.tv_usec = 0;                  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                  {                  {
# Line 107  int igetch(int clear_buf) Line 109  int igetch(int clear_buf)
109    
110                  if (FD_ISSET(STDIN_FILENO, &testfds))                  if (FD_ISSET(STDIN_FILENO, &testfds))
111                  {                  {
112                          len = read(STDIN_FILENO, buf, 255);                          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));
116                            if (len < 0)
117                            {
118                                    if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
119                                    {
120                                            log_error("Read socket error (%d)\n", errno);
121                                    }
122                            }
123    
124                          pos = 0;                          pos = 0;
125    
126                            fcntl(STDIN_FILENO, F_SETFL, flags);
127    
128                          break;                          break;
129                  }                  }
130    
# Line 123  int igetch(int clear_buf) Line 139  int igetch(int clear_buf)
139    
140                  if (c == '\0')                  if (c == '\0')
141                  {                  {
142                          out = c;                          return KEY_NULL;
                         break;  
143                  }                  }
144    
145                  if (c == KEY_CONTROL)                  if (c == KEY_CONTROL)
# Line 240  int igetch_t(long int sec) Line 255  int igetch_t(long int sec)
255          do          do
256          {          {
257                  ch = igetch(0);                  ch = igetch(0);
258          } while ((ch == KEY_TIMEOUT || ch == 0xa) && (time(0) - t_begin < sec));          } while (!SYS_server_exit && ch == KEY_TIMEOUT && (time(0) - t_begin < sec));
259    
260          return ch;          return ch;
261  }  }


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

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