Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/661a2c475079
branches:  trunk
changeset: 536577:661a2c475079
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Wed Sep 18 23:13:39 2002 +0000

description:
select() -> poll()

diffstat:

 usr.sbin/bootp/bootpd/bootpd.c       |  41 +++++++++++++++++------------------
 usr.sbin/bootp/bootpgw/bootpgw.c     |  41 +++++++++++++++++------------------
 usr.sbin/bootp/bootptest/bootptest.c |  17 +++++++-------
 3 files changed, 48 insertions(+), 51 deletions(-)

diffs (278 lines):

diff -r b19db474a272 -r 661a2c475079 usr.sbin/bootp/bootpd/bootpd.c
--- a/usr.sbin/bootp/bootpd/bootpd.c    Wed Sep 18 22:59:36 2002 +0000
+++ b/usr.sbin/bootp/bootpd/bootpd.c    Wed Sep 18 23:13:39 2002 +0000
@@ -22,7 +22,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: bootpd.c,v 1.14 2002/07/13 23:56:39 wiz Exp $");
+__RCSID("$NetBSD: bootpd.c,v 1.15 2002/09/18 23:13:39 mycroft Exp $");
 #endif
 
 /*
@@ -50,6 +50,7 @@
 #include <sys/file.h>
 #include <sys/time.h>
 #include <sys/stat.h>
+#include <sys/poll.h>
 
 #include <net/if.h>
 #include <netinet/in.h>
@@ -143,11 +144,7 @@
  * option defaults
  */
 int debug = 0;                                 /* Debugging flag (level) */
-struct timeval actualtimeout =
-{                                                              /* fifteen minutes */
-       15 * 60L,                                       /* tv_sec */
-       0                                                       /* tv_usec */
-};
+int actualtimeout = 15 * 60000;                        /* fifteen minutes */
 
 /*
  * General
@@ -182,13 +179,14 @@
 int
 main(int argc, char **argv)
 {
-       struct timeval *timeout;
+       int timeout;
        struct bootp *bp;
        struct servent *servp;
        struct hostent *hep;
        char *stmp;
        int n, ba_len, ra_len;
-       int nfound, readfds;
+       int nfound;
+       struct pollfd set[1];
        int standalone;
 
        progname = strrchr(argv[0], '/');
@@ -247,7 +245,7 @@
         * Set defaults that might be changed by option switches.
         */
        stmp = NULL;
-       timeout = &actualtimeout;
+       timeout = actualtimeout;
 
        /*
         * Read switches.
@@ -333,13 +331,13 @@
                                                "%s: invalid timeout specification\n", progname);
                                break;
                        }
-                       actualtimeout.tv_sec = (int32) (60 * n);
+                       actualtimeout = n * 60000;
                        /*
-                        * If the actual timeout is zero, pass a NULL pointer
-                        * to select so it blocks indefinitely, otherwise,
-                        * point to the actual timeout value.
+                        * If the actual timeout is zero, pass INFTIM
+                        * to poll so it blocks indefinitely, otherwise,
+                        * use the actual timeout value.
                         */
-                       timeout = (n > 0) ? &actualtimeout : NULL;
+                       timeout = (n > 0) ? actualtimeout : INFTIM;
                        break;
 
                default:
@@ -402,7 +400,7 @@
                /*
                 * Nuke any timeout value
                 */
-               timeout = NULL;
+               timeout = INFTIM;
 
        } /* if standalone (1st) */
 
@@ -488,12 +486,13 @@
        /*
         * Process incoming requests.
         */
+       set[0].fd = s;
+       set[0].events = POLLIN;
        for (;;) {
-               readfds = 1 << s;
-               nfound = select(s + 1, (fd_set *)&readfds, NULL, NULL, timeout);
+               nfound = poll(set, 1, timeout);
                if (nfound < 0) {
                        if (errno != EINTR) {
-                               report(LOG_ERR, "select: %s", get_errmsg());
+                               report(LOG_ERR, "poll: %s", get_errmsg());
                        }
                        /*
                         * Call readtab() or dumptab() here to avoid the
@@ -509,10 +508,10 @@
                        }
                        continue;
                }
-               if (!(readfds & (1 << s))) {
+               if (nfound == 0) {
                        if (debug > 1)
-                               report(LOG_INFO, "exiting after %ld minutes of inactivity",
-                                          actualtimeout.tv_sec / 60);
+                               report(LOG_INFO, "exiting after %d minutes of inactivity",
+                                          actualtimeout / 60000);
                        exit(0);
                }
                ra_len = sizeof(recv_addr);
diff -r b19db474a272 -r 661a2c475079 usr.sbin/bootp/bootpgw/bootpgw.c
--- a/usr.sbin/bootp/bootpgw/bootpgw.c  Wed Sep 18 22:59:36 2002 +0000
+++ b/usr.sbin/bootp/bootpgw/bootpgw.c  Wed Sep 18 23:13:39 2002 +0000
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: bootpgw.c,v 1.9 2002/07/13 23:59:45 wiz Exp $");
+__RCSID("$NetBSD: bootpgw.c,v 1.10 2002/09/18 23:13:40 mycroft Exp $");
 #endif
 
 /*
@@ -42,6 +42,7 @@
 #include <sys/file.h>
 #include <sys/time.h>
 #include <sys/stat.h>
+#include <sys/poll.h>
 
 #include <net/if.h>
 #include <netinet/in.h>
@@ -115,11 +116,7 @@
  * option defaults
  */
 int debug = 0;                                 /* Debugging flag (level) */
-struct timeval actualtimeout =
-{                                                              /* fifteen minutes */
-       15 * 60L,                                       /* tv_sec */
-       0                                                       /* tv_usec */
-};
+int actualtimeout = 15 * 60000;                        /* fifteen minutes */
 u_int maxhops = 4;                             /* Number of hops allowed for requests. */
 u_int minwait = 3;                             /* Number of seconds client must wait before
                                                   its bootrequest packets are forwarded. */
@@ -148,13 +145,14 @@
 int
 main(int argc, char **argv)
 {
-       struct timeval *timeout;
+       int timeout;
        struct bootp *bp;
        struct servent *servp;
        struct hostent *hep;
        char *stmp;
        int n, ba_len, ra_len;
-       int nfound, readfds;
+       int nfound;
+       struct pollfd set[1];
        int standalone;
 
        progname = strrchr(argv[0], '/');
@@ -210,7 +208,7 @@
         * Set defaults that might be changed by option switches.
         */
        stmp = NULL;
-       timeout = &actualtimeout;
+       timeout = actualtimeout;
        gethostname(myhostname, sizeof(myhostname));
        myhostname[sizeof(myhostname) - 1] = '\0';
        hep = gethostbyname(myhostname);
@@ -290,13 +288,13 @@
                                                "%s: invalid timeout specification\n", progname);
                                break;
                        }
-                       actualtimeout.tv_sec = (int32) (60 * n);
+                       actualtimeout = n * 60000;
                        /*
-                        * If the actual timeout is zero, pass a NULL pointer
-                        * to select so it blocks indefinitely, otherwise,
-                        * point to the actual timeout value.
+                        * If the actual timeout is zero, pass INFTIM
+                        * to poll so it blocks indefinitely, otherwise,
+                        * use the actual timeout value.
                         */
-                       timeout = (n > 0) ? &actualtimeout : NULL;
+                       timeout = (n > 0) ? actualtimeout : INFTIM;
                        break;
 
                case 'w':                               /* wait time */
@@ -370,7 +368,7 @@
                /*
                 * Nuke any timeout value
                 */
-               timeout = NULL;
+               timeout = INFTIM;
 
                /*
                 * Here, bootpd would do:
@@ -431,18 +429,19 @@
        /*
         * Process incoming requests.
         */
+       set[0].fd = s;
+       set[0].events = POLLIN;
        for (;;) {
-               readfds = 1 << s;
-               nfound = select(s + 1, (fd_set *)&readfds, NULL, NULL, timeout);
+               nfound = poll(set, 1, timeout);
                if (nfound < 0) {
                        if (errno != EINTR) {
-                               report(LOG_ERR, "select: %s", get_errmsg());
+                               report(LOG_ERR, "poll: %s", get_errmsg());
                        }
                        continue;
                }
-               if (!(readfds & (1 << s))) {
-                       report(LOG_INFO, "exiting after %ld minutes of inactivity",
-                                  actualtimeout.tv_sec / 60);
+               if (nfound == 0) {
+                       report(LOG_INFO, "exiting after %d minutes of inactivity",
+                                  actualtimeout / 60000);
                        exit(0);
                }
                ra_len = sizeof(clnt_addr);
diff -r b19db474a272 -r 661a2c475079 usr.sbin/bootp/bootptest/bootptest.c
--- a/usr.sbin/bootp/bootptest/bootptest.c      Wed Sep 18 22:59:36 2002 +0000
+++ b/usr.sbin/bootp/bootptest/bootptest.c      Wed Sep 18 23:13:39 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootptest.c,v 1.9 2002/07/14 00:30:02 wiz Exp $        */
+/*     $NetBSD: bootptest.c,v 1.10 2002/09/18 23:13:40 mycroft Exp $   */
 
 /*
  * bootptest.c - Test out a bootp server.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: bootptest.c,v 1.9 2002/07/14 00:30:02 wiz Exp $");
+__RCSID("$NetBSD: bootptest.c,v 1.10 2002/09/18 23:13:40 mycroft Exp $");
 #endif
 
 char *usage = "bootptest [-h] server-name [vendor-data-template-file]";
@@ -47,6 +47,7 @@
 #include <sys/file.h>
 #include <sys/time.h>
 #include <sys/stat.h>
+#include <sys/poll.h>
 
 #include <net/if.h>
 #include <netinet/in.h>
@@ -374,15 +375,13 @@
        bp->bp_secs = secs = 0;
        send_request(s);
        while (1) {
-               struct timeval tv;
-               int readfds;
+               struct pollfd set[1];
 
-               tv.tv_sec = WAITSECS;
-               tv.tv_usec = 0L;
-               readfds = (1 << s);
-               n = select(s + 1, (fd_set *) & readfds, NULL, NULL, &tv);
+               set[0].fd = s;
+               set[0].events = POLLIN;
+               n = poll(set, 1, WAITSECS * 1000);
                if (n < 0) {
-                       perror("select");
+                       perror("poll");
                        break;
                }
                if (n == 0) {



Home | Main Index | Thread Index | Old Index