From 19e51cb44f1ebcfd7a5da99a5f8da9addfdbba4f Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Mon, 11 Aug 2003 21:10:55 +0000 Subject: use poll to replace the fd_set overflows. some input from fgsch; millert ok --- usr.bin/talk/io.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'usr.bin/talk/io.c') diff --git a/usr.bin/talk/io.c b/usr.bin/talk/io.c index d90b77d2705..9734bc13311 100644 --- a/usr.bin/talk/io.c +++ b/usr.bin/talk/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.13 2003/06/10 22:20:53 deraadt Exp $ */ +/* $OpenBSD: io.c,v 1.14 2003/08/11 21:10:54 deraadt Exp $ */ /* $NetBSD: io.c,v 1.4 1994/12/09 02:14:20 jtc Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: io.c,v 1.13 2003/06/10 22:20:53 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: io.c,v 1.14 2003/08/11 21:10:54 deraadt Exp $"; #endif /* not lint */ /* @@ -47,10 +47,11 @@ static char rcsid[] = "$OpenBSD: io.c,v 1.13 2003/06/10 22:20:53 deraadt Exp $"; #include #include #include +#include #include #include -#define A_LONG_TIME 10000000 +#define A_LONG_TIME 1000000 volatile sig_atomic_t gotwinch = 0; @@ -60,11 +61,9 @@ volatile sig_atomic_t gotwinch = 0; void talk(void) { - fd_set read_template, read_set; - int nb; + struct pollfd fds[2]; char buf[BUFSIZ]; - struct timeval wait; - int maxfd = 0; + int nb; #if defined(NCURSES_VERSION) || defined(beep) message("Connection established"); @@ -80,38 +79,31 @@ talk(void) * Wait on both the other process (sockt_mask) and * standard input ( STDIN_MASK ) */ - FD_ZERO(&read_template); - FD_SET(fileno(stdin), &read_template); - if (fileno(stdin) > maxfd) - maxfd = fileno(stdin); - FD_SET(sockt, &read_template); - if (sockt > maxfd) - maxfd = sockt; + fds[0].fd = fileno(stdin); + fds[0].events = POLLIN; + fds[1].fd = sockt; + fds[1].events = POLLIN; + for (;;) { - read_set = read_template; - wait.tv_sec = A_LONG_TIME; - wait.tv_usec = 0; - nb = select(maxfd + 1, &read_set, 0, 0, &wait); + nb = poll(fds, 2, A_LONG_TIME * 1000); if (gotwinch) { resize_display(); gotwinch = 0; } if (nb <= 0) { - if (errno == EINTR) { - read_set = read_template; + if (errno == EINTR) continue; - } /* panic, we don't know what happened */ quit("Unexpected error from select", 1); } - if (FD_ISSET(sockt, &read_set)) { + if (fds[1].revents & POLLIN) { /* There is data on sockt */ nb = read(sockt, buf, sizeof buf); if (nb <= 0) quit("Connection closed. Exiting", 0); display(&his_win, buf, nb); } - if (FD_ISSET(fileno(stdin), &read_set)) { + if (fds[0].revents & POLLIN) { /* * We can't make the tty non_blocking, because * curses's output routines would screw up -- cgit v1.2.3