Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin select() -> poll()



details:   https://anonhg.NetBSD.org/src/rev/f933f9f10489
branches:  trunk
changeset: 536766:f933f9f10489
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Sat Sep 21 18:24:40 2002 +0000

description:
select() -> poll()

diffstat:

 sbin/mount_portal/mount_portal.c |  16 ++++++++--------
 sbin/ping/ping.c                 |  21 +++++++--------------
 sbin/ping6/ping6.c               |  26 ++++++++++----------------
 3 files changed, 25 insertions(+), 38 deletions(-)

diffs (194 lines):

diff -r ad7b145e8c3b -r f933f9f10489 sbin/mount_portal/mount_portal.c
--- a/sbin/mount_portal/mount_portal.c  Sat Sep 21 18:19:30 2002 +0000
+++ b/sbin/mount_portal/mount_portal.c  Sat Sep 21 18:24:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mount_portal.c,v 1.20 2002/07/20 08:36:27 grant Exp $  */
+/*     $NetBSD: mount_portal.c,v 1.21 2002/09/21 18:32:46 mycroft Exp $        */
 
 /*
  * Copyright (c) 1992, 1993, 1994
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)mount_portal.c     8.6 (Berkeley) 4/26/95";
 #else
-__RCSID("$NetBSD: mount_portal.c,v 1.20 2002/07/20 08:36:27 grant Exp $");
+__RCSID("$NetBSD: mount_portal.c,v 1.21 2002/09/21 18:32:46 mycroft Exp $");
 #endif
 #endif /* not lint */
 
@@ -60,6 +60,7 @@
 
 #include <err.h>
 #include <errno.h>
+#include <poll.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -238,7 +239,7 @@
                int len2 = sizeof(un2);
                int so2;
                pid_t pid;
-               fd_set fdset;
+               struct pollfd fdset[1];
 
                /*
                 * Check whether we need to re-read the configuration file
@@ -254,14 +255,13 @@
                 * Will get EINTR if a signal has arrived, so just
                 * ignore that error code
                 */
-               FD_ZERO(&fdset);
-               FD_SET(so, &fdset);
-               rc = select(so+1, &fdset, (fd_set *)0, (fd_set *)0,
-                   (struct timeval *)0);
+               fdset[0].fd = so;
+               fdset[0].events = POLLIN;
+               rc = poll(fdset, 1, INFTIM);
                if (rc < 0) {
                        if (errno == EINTR)
                                continue;
-                       syslog(LOG_ERR, "select: %m");
+                       syslog(LOG_ERR, "poll: %m");
                        exit(1);
                }
                if (rc == 0)
diff -r ad7b145e8c3b -r f933f9f10489 sbin/ping/ping.c
--- a/sbin/ping/ping.c  Sat Sep 21 18:19:30 2002 +0000
+++ b/sbin/ping/ping.c  Sat Sep 21 18:24:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ping.c,v 1.66 2002/08/12 18:24:53 matt Exp $   */
+/*     $NetBSD: ping.c,v 1.67 2002/09/21 18:24:40 mycroft Exp $        */
 
 /*
  * Copyright (c) 1989, 1993
@@ -62,7 +62,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ping.c,v 1.66 2002/08/12 18:24:53 matt Exp $");
+__RCSID("$NetBSD: ping.c,v 1.67 2002/09/21 18:24:40 mycroft Exp $");
 #endif
 
 #include <stdio.h>
@@ -77,6 +77,7 @@
 #include <termios.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <poll.h>
 #include <limits.h>
 #include <math.h>
 #include <string.h>
@@ -664,9 +665,7 @@
        struct sockaddr_in from;
        int fromlen;
        double sec, last, d_last;
-       struct timeval timeout;
-       fd_set *fdmaskp;
-       size_t nfdmask;
+       struct pollfd fdmaskp[1];
 
        (void)gettimeofday(&clear_cache,0);
        if (maxwait != 0) {
@@ -677,10 +676,6 @@
                d_last = 365*24*60*60;
        }
 
-       nfdmask = howmany(s + 1, NFDBITS) * sizeof(fd_mask);
-       if ((fdmaskp = malloc(nfdmask)) == NULL)
-               err(1, "malloc");
-       memset(fdmaskp, 0, nfdmask);
        do {
                (void)gettimeofday(&now,0);
 
@@ -713,10 +708,9 @@
                }
 
 
-               sec_to_timeval(sec, &timeout);
-
-               FD_SET(s, fdmaskp);
-               cc = select(s+1, fdmaskp, 0, 0, &timeout);
+               fdmaskp[0].fd = s;
+               fdmaskp[0].events = POLLIN;
+               cc = poll(fdmaskp, 1, (int)(sec * 1000));
                if (cc <= 0) {
                        if (cc < 0) {
                                if (errno == EINTR)
@@ -744,7 +738,6 @@
 
        } while (nreceived < npackets
                 && (nreceived == 0 || !(pingflags & F_ONCE)));
-       free(fdmaskp);
 
        finish(0);
 }
diff -r ad7b145e8c3b -r f933f9f10489 sbin/ping6/ping6.c
--- a/sbin/ping6/ping6.c        Sat Sep 21 18:19:30 2002 +0000
+++ b/sbin/ping6/ping6.c        Sat Sep 21 18:24:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ping6.c,v 1.47 2002/09/08 14:31:41 itojun Exp $        */
+/*     $NetBSD: ping6.c,v 1.48 2002/09/21 18:30:05 mycroft Exp $       */
 /*     $KAME: ping6.c,v 1.160 2002/09/08 14:28:18 itojun Exp $ */
 
 /*
@@ -81,7 +81,7 @@
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ping6.c,v 1.47 2002/09/08 14:31:41 itojun Exp $");
+__RCSID("$NetBSD: ping6.c,v 1.48 2002/09/21 18:30:05 mycroft Exp $");
 #endif
 #endif
 
@@ -133,6 +133,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <poll.h>
 
 #ifdef IPSEC
 #include <netinet6/ah.h>
@@ -290,10 +291,9 @@
 {
        struct itimerval itimer;
        struct sockaddr_in6 from;
-       struct timeval timeout, *tv;
+       int timeout;
        struct addrinfo hints;
-       fd_set *fdmaskp;
-       int fdmasks;
+       struct pollfd fdmaskp[1];
        int cc, i;
        int ch, hold, packlen, preload, optval, ret_ga;
        u_char *datap, *packet;
@@ -1043,10 +1043,6 @@
                        retransmit();
        }
 
-       fdmasks = howmany(s + 1, NFDBITS) * sizeof(fd_mask);
-       if ((fdmaskp = malloc(fdmasks)) == NULL)
-               err(1, "malloc");
-
        seenalrm = seenint = 0;
 #ifdef SIGINFO
        seeninfo = 0;
@@ -1079,14 +1075,12 @@
 
                if (options & F_FLOOD) {
                        (void)pinger();
-                       timeout.tv_sec = 0;
-                       timeout.tv_usec = 10000;
-                       tv = &timeout;
+                       timeout = 10;
                } else
-                       tv = NULL;
-               memset(fdmaskp, 0, fdmasks);
-               FD_SET(s, fdmaskp);
-               cc = select(s + 1, fdmaskp, NULL, NULL, tv);
+                       timeout = INFTIM;
+               fdmaskp[0].fd = s;
+               fdmaskp[0].events = POLLIN;
+               cc = poll(fdmaskp, 1, timeout);
                if (cc < 0) {
                        if (errno != EINTR) {
                                warn("select");



Home | Main Index | Thread Index | Old Index