File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 10
10
#include <fcntl.h>
11
11
#include <poll.h>
12
12
#include <errno.h>
13
+ #include <termios.h>
13
14
#include <sys/socket.h>
15
+ #include <sys/ioctl.h>
14
16
15
17
#define MSG_MAX 512 /* guaranteed max message length */
16
18
#define CHA_MAX 200 /* guaranteed max channel length */
@@ -258,6 +260,21 @@ handle_user_input(void) {
258
260
}
259
261
}
260
262
263
+ static int
264
+ keyboardhit () {
265
+ struct termios save , tp ;
266
+ int byteswaiting ;
267
+
268
+ tcgetattr (STDIN_FILENO , & tp );
269
+ save = tp ;
270
+ tp .c_lflag &= ~ICANON ;
271
+ tcsetattr (STDIN_FILENO , TCSANOW , & tp );
272
+ ioctl (STDIN_FILENO , FIONREAD , & byteswaiting );
273
+ tcsetattr (STDIN_FILENO , TCSANOW , & save );
274
+
275
+ return byteswaiting ;
276
+ }
277
+
261
278
int
262
279
main (int argc , char * * argv ) {
263
280
@@ -310,7 +327,7 @@ main(int argc, char **argv) {
310
327
if (fds [0 ].revents & POLLIN ) {
311
328
handle_user_input ();
312
329
}
313
- if (fds [1 ].revents & POLLIN ) {
330
+ if (fds [1 ].revents & POLLIN && ( keyboardhit () < 1 ) ) {
314
331
int rc = handle_server_message ();
315
332
if (rc != 0 ) {
316
333
if (rc == -2 ) return EXIT_FAILURE ;
You can’t perform that action at this time.
0 commit comments