From e92308f21040871c370483ec9857f01353884c79 Mon Sep 17 00:00:00 2001 From: mycroft Date: Fri, 20 Sep 2002 15:47:19 +0000 Subject: [PATCH] select() -> poll() --- games/hunt/hunt/hunt.c | 20 +++++++++----------- games/hunt/hunt/playit.c | 26 ++++++++++++-------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/games/hunt/hunt/hunt.c b/games/hunt/hunt/hunt.c index 000755c8a598..9034b27f6a80 100644 --- a/games/hunt/hunt/hunt.c +++ b/games/hunt/hunt/hunt.c @@ -1,4 +1,4 @@ -/* $NetBSD: hunt.c,v 1.12 2001/02/05 00:40:45 christos Exp $ */ +/* $NetBSD: hunt.c,v 1.13 2002/09/20 15:47:19 mycroft Exp $ */ /* * Hunt * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold @@ -7,12 +7,13 @@ #include #ifndef lint -__RCSID("$NetBSD: hunt.c,v 1.12 2001/02/05 00:40:45 christos Exp $"); +__RCSID("$NetBSD: hunt.c,v 1.13 2002/09/20 15:47:19 mycroft Exp $"); #endif /* not lint */ # include # include # include +# include # include # include # include @@ -398,8 +399,7 @@ list_drivers() static SOCKET *listv; static unsigned int listmax; unsigned int listc; - fd_set mask; - struct timeval wait; + struct pollfd set[1]; if (initial) { /* do one time initialization */ # ifndef BROADCAST @@ -497,8 +497,8 @@ list_drivers() get_response: namelen = DAEMON_SIZE; errno = 0; - wait.tv_sec = 1; - wait.tv_usec = 0; + set[0].fd = test_socket; + set[0].events = POLLIN; for (;;) { if (listc + 1 >= listmax) { listmax += 20; @@ -506,9 +506,7 @@ get_response: listmax * sizeof(SOCKET)); } - FD_ZERO(&mask); - FD_SET(test_socket, &mask); - if (select(test_socket + 1, &mask, NULL, NULL, &wait) == 1 && + if (poll(set, 1, 1000) == 1 && recvfrom(test_socket, (char *) &port_num, sizeof(port_num), 0, (struct sockaddr *) &listv[listc], &namelen) > 0) { /* @@ -526,8 +524,8 @@ get_response: } if (errno != 0 && errno != EINTR) { - warn("select/recvfrom"); - leave(1, "select/recvfrom"); + warn("poll/recvfrom"); + leave(1, "poll/recvfrom"); /* NOTREACHED */ } diff --git a/games/hunt/hunt/playit.c b/games/hunt/hunt/playit.c index 53fd6b34c080..381ef1303922 100644 --- a/games/hunt/hunt/playit.c +++ b/games/hunt/hunt/playit.c @@ -1,4 +1,4 @@ -/* $NetBSD: playit.c,v 1.4 1997/10/20 00:37:15 lukem Exp $ */ +/* $NetBSD: playit.c,v 1.5 2002/09/20 15:47:19 mycroft Exp $ */ /* * Hunt * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold @@ -7,10 +7,11 @@ #include #ifndef lint -__RCSID("$NetBSD: playit.c,v 1.4 1997/10/20 00:37:15 lukem Exp $"); +__RCSID("$NetBSD: playit.c,v 1.5 2002/09/20 15:47:19 mycroft Exp $"); #endif /* not lint */ # include +# include # include # include # include @@ -217,26 +218,23 @@ out: static unsigned char getchr() { - fd_set readfds, s_readfds; - int nfds, s_nfds; + struct pollfd set[2]; + int nfds; - FD_ZERO(&s_readfds); - FD_SET(Socket, &s_readfds); - FD_SET(STDIN, &s_readfds); - s_nfds = (Socket > STDIN) ? Socket : STDIN; - s_nfds++; + set[0].fd = Socket; + set[0].events = POLLIN; + set[1].fd = STDIN; + set[1].events = POLLIN; one_more_time: do { errno = 0; - readfds = s_readfds; - nfds = s_nfds; - nfds = select(nfds, &readfds, NULL, NULL, NULL); + nfds = poll(set, 2, INFTIM); } while (nfds <= 0 && errno == EINTR); - if (FD_ISSET(STDIN, &readfds)) + if (set[1].revents && POLLIN) send_stuff(); - if (! FD_ISSET(Socket, &readfds)) + if (! (set[0].revents & POLLIN)) goto one_more_time; icnt = read(Socket, ibuf, sizeof ibuf); if (icnt < 0) {