summaryrefslogtreecommitdiff
path: root/usr.bin/talk/io.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-08-11 21:10:55 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-08-11 21:10:55 +0000
commit19e51cb44f1ebcfd7a5da99a5f8da9addfdbba4f (patch)
tree73050c7f1c9ab176e7beca50a5aeffd5c6ae01c0 /usr.bin/talk/io.c
parentba29d03891af8f040301c2d85702dda393c1f77a (diff)
use poll to replace the fd_set overflows. some input from fgsch; millert ok
Diffstat (limited to 'usr.bin/talk/io.c')
-rw-r--r--usr.bin/talk/io.c38
1 files changed, 15 insertions, 23 deletions
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