diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-08-11 21:10:55 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-08-11 21:10:55 +0000 |
commit | 19e51cb44f1ebcfd7a5da99a5f8da9addfdbba4f (patch) | |
tree | 73050c7f1c9ab176e7beca50a5aeffd5c6ae01c0 /usr.bin | |
parent | ba29d03891af8f040301c2d85702dda393c1f77a (diff) |
use poll to replace the fd_set overflows. some input from fgsch; millert ok
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/talk/ctl_transact.c | 22 | ||||
-rw-r--r-- | usr.bin/talk/io.c | 38 |
2 files changed, 23 insertions, 37 deletions
diff --git a/usr.bin/talk/ctl_transact.c b/usr.bin/talk/ctl_transact.c index 889b2ae6e0f..9e84e16fbc2 100644 --- a/usr.bin/talk/ctl_transact.c +++ b/usr.bin/talk/ctl_transact.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ctl_transact.c,v 1.8 2003/06/03 02:56:17 millert Exp $ */ +/* $OpenBSD: ctl_transact.c,v 1.9 2003/08/11 21:10:54 deraadt Exp $ */ /* $NetBSD: ctl_transact.c,v 1.3 1994/12/09 02:14:12 jtc Exp $ */ /* @@ -34,13 +34,14 @@ #if 0 static char sccsid[] = "@(#)ctl_transact.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: ctl_transact.c,v 1.8 2003/06/03 02:56:17 millert Exp $"; +static char rcsid[] = "$OpenBSD: ctl_transact.c,v 1.9 2003/08/11 21:10:54 deraadt Exp $"; #endif /* not lint */ #include "talk.h" #include <sys/time.h> #include <errno.h> #include <unistd.h> +#include <poll.h> #include "talk_ctl.h" #define CTL_WAIT 2 /* time to wait for a response, in seconds */ @@ -57,23 +58,20 @@ ctl_transact(target, msg, type, rp) int type; CTL_RESPONSE *rp; { - fd_set read_mask, ctl_mask; + struct pollfd pfd[1]; int nready, cc; - struct timeval wait; msg.type = type; daemon_addr.sin_addr = target; daemon_addr.sin_port = daemon_port; - FD_ZERO(&ctl_mask); - FD_SET(ctl_sockt, &ctl_mask); + pfd[0].fd = ctl_sockt; + pfd[0].events = POLLIN; /* * Keep sending the message until a response of * the proper type is obtained. */ do { - wait.tv_sec = CTL_WAIT; - wait.tv_usec = 0; /* resend message until a response is obtained */ do { cc = sendto(ctl_sockt, (char *)&msg, sizeof (msg), 0, @@ -84,8 +82,7 @@ ctl_transact(target, msg, type, rp) continue; quit("Error on write to talk daemon", 1); } - read_mask = ctl_mask; - nready = select(ctl_sockt + 1, &read_mask, 0, 0, &wait); + nready = poll(pfd, 1, CTL_WAIT * 1000); if (nready < 0) { if (errno == EINTR) continue; @@ -104,10 +101,7 @@ ctl_transact(target, msg, type, rp) continue; quit("Error on read from talk daemon", 1); } - read_mask = ctl_mask; - /* an immediate poll */ - timerclear(&wait); - nready = select(ctl_sockt + 1, &read_mask, 0, 0, &wait); + nready = poll(pfd, 1, 0); } while (nready > 0 && (rp->vers != TALK_VERSION || rp->type != type)); } while (rp->vers != TALK_VERSION || rp->type != type); 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 <sys/ioctl.h> #include <sys/time.h> #include <stdio.h> +#include <poll.h> #include <errno.h> #include <unistd.h> -#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 |