7
7
#include <stdlib.h>
8
8
#include <string.h>
9
9
#include <netdb.h>
10
- #include <sys/ioctl.h>
11
10
#include <fcntl.h>
11
+ #include <sys/select.h>
12
12
#include <sys/wait.h>
13
13
#include <termios.h>
14
14
@@ -29,14 +29,17 @@ kbhit(void)
29
29
{
30
30
int byteswaiting ;
31
31
struct termios term ;
32
-
32
+ fd_set fds ;
33
+ struct timespec ts = {0 };
33
34
tcgetattr (0 , & term );
34
35
35
36
struct termios term2 = term ;
36
37
37
38
term2 .c_lflag &= ~ICANON ;
38
39
tcsetattr (0 , TCSANOW , & term2 );
39
- ioctl (0 , FIONREAD , & byteswaiting );
40
+ FD_ZERO (& fds );
41
+ FD_SET (0 , & fds );
42
+ byteswaiting = pselect (1 , & fds , NULL , NULL , & ts , NULL );
40
43
tcsetattr (0 , TCSANOW , & term );
41
44
42
45
return byteswaiting > 0 ;
@@ -58,11 +61,11 @@ raw(char *fmt, ...) {
58
61
static void
59
62
con (void )
60
63
{
61
- struct addrinfo hints , * res ;
64
+ struct addrinfo * res , hints = {
65
+ .ai_family = AF_INET ,
66
+ .ai_socktype = SOCK_STREAM
67
+ };
62
68
63
- memset (& hints , 0 , sizeof hints );
64
- hints .ai_family = AF_INET ;
65
- hints .ai_socktype = SOCK_STREAM ;
66
69
getaddrinfo (host , port , & hints , & res );
67
70
conn = socket (res -> ai_family , res -> ai_socktype , res -> ai_protocol );
68
71
connect (conn , res -> ai_addr , res -> ai_addrlen );
@@ -85,7 +88,6 @@ printw(const char *format, ...)
85
88
if (strlen (line ) <= CMAX ) printf ("%s" , line );
86
89
else if (strlen (line ) > CMAX )
87
90
{
88
-
89
91
for (i = 0 ; i < CMAX ; i ++ )
90
92
{
91
93
if (line [i ] == ' ' ) s1 = i ;
@@ -106,7 +108,7 @@ printw(const char *format, ...)
106
108
}
107
109
}
108
110
}
109
-
111
+
110
112
}
111
113
112
114
static void
@@ -231,11 +233,11 @@ main(int argc, char **argv)
231
233
{
232
234
case 'q' :
233
235
write (fd [1 ], "quit" , sizeof ("quit" ));
234
- break ;
236
+ break ;
235
237
case 'm' :
236
238
while (isspace (* cmd_val )) cmd_val ++ ;
237
239
dprintf (fd [1 ], "privmsg #%s :%s" , chan , cmd_val );
238
- break ;
240
+ break ;
239
241
}
240
242
}
241
243
else
@@ -245,6 +247,5 @@ main(int argc, char **argv)
245
247
fflush (stdout );
246
248
}
247
249
}
248
-
249
250
return 0 ;
250
251
}
0 commit comments