Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/timed select() -> poll(), nanosleep()



details:   https://anonhg.NetBSD.org/src/rev/c85e6e3a1abe
branches:  trunk
changeset: 536583:c85e6e3a1abe
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Thu Sep 19 00:01:33 2002 +0000

description:
select() -> poll(), nanosleep()

diffstat:

 usr.sbin/timed/timed/globals.h |   3 +-
 usr.sbin/timed/timed/measure.c |  21 +++++++----------
 usr.sbin/timed/timed/readmsg.c |  13 +++++------
 usr.sbin/timed/timed/slave.c   |  11 ++++-----
 usr.sbin/timed/timedc/cmds.c   |  48 +++++++++++++++++++----------------------
 usr.sbin/timed/timedc/timedc.h |   4 ++-
 6 files changed, 47 insertions(+), 53 deletions(-)

diffs (truncated from 316 to 300 lines):

diff -r 9c949eb48db6 -r c85e6e3a1abe usr.sbin/timed/timed/globals.h
--- a/usr.sbin/timed/timed/globals.h    Wed Sep 18 23:33:37 2002 +0000
+++ b/usr.sbin/timed/timed/globals.h    Thu Sep 19 00:01:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: globals.h,v 1.7 2001/09/02 00:13:06 reinoud Exp $      */
+/*     $NetBSD: globals.h,v 1.8 2002/09/19 00:01:33 mycroft Exp $      */
 
 /*-
  * Copyright (c) 1985 The Regents of the University of California.
@@ -38,6 +38,7 @@
 #include <sys/param.h>
 #include <sys/time.h>
 #include <sys/socket.h>
+#include <sys/poll.h>
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
diff -r 9c949eb48db6 -r c85e6e3a1abe usr.sbin/timed/timed/measure.c
--- a/usr.sbin/timed/timed/measure.c    Wed Sep 18 23:33:37 2002 +0000
+++ b/usr.sbin/timed/timed/measure.c    Thu Sep 19 00:01:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: measure.c,v 1.9 2002/07/10 22:44:22 wiz Exp $  */
+/*     $NetBSD: measure.c,v 1.10 2002/09/19 00:01:33 mycroft Exp $     */
 
 /*-
  * Copyright (c) 1985, 1993 The Regents of the University of California.
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)measure.c  8.2 (Berkeley) 3/26/95";
 #else
-__RCSID("$NetBSD: measure.c,v 1.9 2002/07/10 22:44:22 wiz Exp $");
+__RCSID("$NetBSD: measure.c,v 1.10 2002/09/19 00:01:33 mycroft Exp $");
 #endif
 #endif /* not lint */
 
@@ -77,7 +77,7 @@
        int measure_status;
        int rcvcount, trials;
        int cc, count;
-       fd_set ready;
+       struct pollfd set[1];
        long sendtime, recvtime, histime1, histime2;
        long idelta, odelta, total;
        long min_idelta, min_odelta;
@@ -102,15 +102,14 @@
                }
        }
            
+       set[0].fd = sock_raw;
+       set[0].events = POLLIN;
 
        /*
         * empty the icmp input queue
         */
-       FD_ZERO(&ready);
        for (;;) {
-               tout.tv_sec = tout.tv_usec = 0;
-               FD_SET(sock_raw, &ready);
-               if (select(sock_raw+1, &ready, 0,0, &tout)) {
+               if (poll(set, 1, 0)) {
                        length = sizeof(struct sockaddr_in);
                        cc = recvfrom(sock_raw, (char *)packet, PACKET_IN, 0,
                                      0,&length);
@@ -134,14 +133,14 @@
        oicp->icmp_ttime = 0;
        oicp->icmp_seq = seqno;
 
-       FD_ZERO(&ready);
-
        (void)gettimeofday(&tdone, 0);
        mstotvround(&tout, maxmsec);
        timeradd(&tdone, &tout, &tdone);        /* when we give up */
 
        mstotvround(&twait, wmsec);
 
+       tout.tv_sec = 0;
+       tout.tv_usec = 0;
        rcvcount = 0;
        while (rcvcount < MSGS) {
                (void)gettimeofday(&tcur, 0);
@@ -177,9 +176,7 @@
                        if (tout.tv_sec < 0)
                                tout.tv_sec = 0;
 
-                       FD_SET(sock_raw, &ready);
-                       count = select(sock_raw+1, &ready, (fd_set *)0,
-                                      (fd_set *)0, &tout);
+                       count = poll(set, 1, tout.tv_sec * 1000 + tout.tv_usec / 1000);
                        (void)gettimeofday(&tcur, (struct timezone *)0);
                        if (count <= 0)
                                break;
diff -r 9c949eb48db6 -r c85e6e3a1abe usr.sbin/timed/timed/readmsg.c
--- a/usr.sbin/timed/timed/readmsg.c    Wed Sep 18 23:33:37 2002 +0000
+++ b/usr.sbin/timed/timed/readmsg.c    Thu Sep 19 00:01:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: readmsg.c,v 1.12 2002/07/06 22:08:31 wiz Exp $ */
+/*     $NetBSD: readmsg.c,v 1.13 2002/09/19 00:01:33 mycroft Exp $     */
 
 /*-
  * Copyright (c) 1985, 1993 The Regents of the University of California.
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)readmsg.c  8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: readmsg.c,v 1.12 2002/07/06 22:08:31 wiz Exp $");
+__RCSID("$NetBSD: readmsg.c,v 1.13 2002/09/19 00:01:33 mycroft Exp $");
 #endif
 #endif /* not lint */
 
@@ -81,7 +81,7 @@
        struct netinfo *netfrom)
 {
        int length;
-       fd_set ready;
+       struct pollfd set[1];
        static struct tsplist *head = &msgslist;
        static struct tsplist *tail = &msgslist;
        static int msgcnt = 0;
@@ -175,7 +175,8 @@
 
        (void)gettimeofday(&rtout, 0);
        timeradd(&rtout, intvl, &rtout);
-       FD_ZERO(&ready);
+       set[0].fd = sock;
+       set[0].events = POLLIN;
        for (;;) {
                (void)gettimeofday(&rtime, 0);
                timersub(&rtout, &rtime, &rwait);
@@ -200,9 +201,7 @@
                                traceoff("Tracing ended for cause at %s\n");
                }
 
-               FD_SET(sock, &ready);
-               if (!select(sock+1, &ready, (fd_set *)0, (fd_set *)0,
-                          &rwait)) {
+               if (!poll(set, 1, rwait.tv_sec * 1000 + rwait.tv_usec / 1000)) {
                        if (rwait.tv_sec == 0 && rwait.tv_usec == 0)
                                return(0);
                        continue;
diff -r 9c949eb48db6 -r c85e6e3a1abe usr.sbin/timed/timed/slave.c
--- a/usr.sbin/timed/timed/slave.c      Wed Sep 18 23:33:37 2002 +0000
+++ b/usr.sbin/timed/timed/slave.c      Thu Sep 19 00:01:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: slave.c,v 1.11 2002/07/10 22:44:22 wiz Exp $   */
+/*     $NetBSD: slave.c,v 1.12 2002/09/19 00:01:33 mycroft Exp $       */
 
 /*-
  * Copyright (c) 1985, 1993 The Regents of the University of California.
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)slave.c    8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: slave.c,v 1.11 2002/07/10 22:44:22 wiz Exp $");
+__RCSID("$NetBSD: slave.c,v 1.12 2002/09/19 00:01:33 mycroft Exp $");
 #endif
 #endif /* not lint */
 
@@ -683,12 +683,11 @@
 static void
 answerdelay(void)
 {
-       struct timeval timeout;
+       struct timespec timeout;
 
        timeout.tv_sec = 0;
-       timeout.tv_usec = delay1;
+       timeout.tv_nsec = delay1 * 1000;
 
-       (void)select(0, (fd_set *)NULL, (fd_set *)NULL, (fd_set *)NULL,
-           &timeout);
+       nanosleep(&timeout, NULL);
        return;
 }
diff -r 9c949eb48db6 -r c85e6e3a1abe usr.sbin/timed/timedc/cmds.c
--- a/usr.sbin/timed/timedc/cmds.c      Wed Sep 18 23:33:37 2002 +0000
+++ b/usr.sbin/timed/timedc/cmds.c      Thu Sep 19 00:01:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.11 2002/07/06 22:01:40 wiz Exp $    */
+/*     $NetBSD: cmds.c,v 1.12 2002/09/19 00:01:33 mycroft Exp $        */
 
 /*-
  * Copyright (c) 1985, 1993 The Regents of the University of California.
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.2 (Berkeley) 3/26/95";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.11 2002/07/06 22:01:40 wiz Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.12 2002/09/19 00:01:33 mycroft Exp $");
 #endif
 #endif /* not lint */
 
@@ -85,16 +85,18 @@
 {
        int i;
        int trials;
-       struct timeval tout, now;
-       fd_set ready;
+       int tout;
+       struct timeval now;
+       struct pollfd set[1];
        struct sockaddr from;
        int fromlen;
        unsigned long sec;
 
 
        /* wait 2 seconds between 10 tries */
-       tout.tv_sec = 2;
-       tout.tv_usec = 0;
+       tout = 2000;
+       set[0].fd = sock;
+       set[0].events = POLLIN;
        for (trials = 0; trials < 10; trials++) {
                /* ask for the time */
                sec = 0;
@@ -105,14 +107,11 @@
                }
 
                for (;;) {
-                       FD_ZERO(&ready);
-                       FD_SET(sock, &ready);
-                       i = select(sock+1, &ready, (fd_set *)0,
-                                  (fd_set *)0, &tout);
+                       i = poll(set, 1, tout);
                        if (i < 0) {
                                if (errno == EINTR)
                                        continue;
-                               perror("select(date read)");
+                               perror("poll(date read)");
                                return 0;
                        }
                        if (0 == i)
@@ -269,11 +268,11 @@
 msite(int argc, char *argv[])
 {
        int cc;
-       fd_set ready;
+       struct pollfd set[1];
        struct sockaddr_in dest;
        int i, length;
        struct sockaddr from;
-       struct timeval tout;
+       int tout;
        struct tsp msg;
        struct servent *srvp;
        char *tgtname;
@@ -293,6 +292,9 @@
 
        (void)gethostname(myname, sizeof(myname));
        i = 1;
+       tout = 15000;
+       set[0].fd = sock;
+       set[0].events = POLLIN;
        do {
                tgtname = (i >= argc) ? myname : argv[i];
                hp = gethostbyname(tgtname);
@@ -314,12 +316,7 @@
                        continue;
                }
 
-               tout.tv_sec = 15;
-               tout.tv_usec = 0;
-               FD_ZERO(&ready);
-               FD_SET(sock, &ready);
-               if (select(FD_SETSIZE, &ready, (fd_set *)0, (fd_set *)0,
-                          &tout)) {
+               if (poll(set, 1, tout)) {
                        length = sizeof(struct sockaddr);
                        cc = recvfrom(sock, &msg, sizeof(struct tsp), 0,
                                      &from, &length);
@@ -410,10 +407,10 @@
        int onflag;
        int length;
        int cc;
-       fd_set ready;
+       struct pollfd set[1];
        struct sockaddr_in dest;
        struct sockaddr from;
-       struct timeval tout;
+       int tout;
        struct tsp msg;
        struct servent *srvp;
 
@@ -451,11 +448,10 @@
                return;
        }
 
-       tout.tv_sec = 5;
-       tout.tv_usec = 0;
-       FD_ZERO(&ready);
-       FD_SET(sock, &ready);
-       if (select(FD_SETSIZE, &ready, (fd_set *)0, (fd_set *)0, &tout)) {
+       tout = 5000;
+       set[0].fd = sock;
+       set[0].events = POLLIN;
+       if (poll(set, 1, tout)) {
                length = sizeof(struct sockaddr);
                cc = recvfrom(sock, &msg, sizeof(struct tsp), 0,
                              &from, &length);
diff -r 9c949eb48db6 -r c85e6e3a1abe usr.sbin/timed/timedc/timedc.h
--- a/usr.sbin/timed/timedc/timedc.h    Wed Sep 18 23:33:37 2002 +0000



Home | Main Index | Thread Index | Old Index