Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/a945fffc34f0
branches:  trunk
changeset: 536575:a945fffc34f0
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Wed Sep 18 20:58:56 2002 +0000

description:
select() -> poll()

diffstat:

 libexec/telnetd/defs.h    |   3 +-
 libexec/telnetd/telnetd.c |  72 ++++++++++++++++++++--------------------------
 libexec/telnetd/utility.c |  18 ++++-------
 usr.sbin/apmd/apmd.c      |  31 +++++++++----------
 4 files changed, 56 insertions(+), 68 deletions(-)

diffs (truncated from 309 to 300 lines):

diff -r ee7b3dc4ca88 -r a945fffc34f0 libexec/telnetd/defs.h
--- a/libexec/telnetd/defs.h    Wed Sep 18 20:57:02 2002 +0000
+++ b/libexec/telnetd/defs.h    Wed Sep 18 20:58:56 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.11 2002/05/26 00:02:08 wiz Exp $    */
+/*     $NetBSD: defs.h,v 1.12 2002/09/18 20:58:56 mycroft Exp $        */
 
 /*
  * Copyright (c) 1989, 1993
@@ -72,6 +72,7 @@
 #include <sys/file.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <sys/poll.h>
 #ifndef        FILIO_H
 #include <sys/ioctl.h>
 #else
diff -r ee7b3dc4ca88 -r a945fffc34f0 libexec/telnetd/telnetd.c
--- a/libexec/telnetd/telnetd.c Wed Sep 18 20:57:02 2002 +0000
+++ b/libexec/telnetd/telnetd.c Wed Sep 18 20:58:56 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: telnetd.c,v 1.33 2002/08/20 13:58:22 christos Exp $    */
+/*     $NetBSD: telnetd.c,v 1.34 2002/09/18 20:58:56 mycroft Exp $     */
 
 /*
  * Copyright (C) 1997 and 1998 WIDE Project.
@@ -69,7 +69,7 @@
 #if 0
 static char sccsid[] = "@(#)telnetd.c  8.4 (Berkeley) 5/30/95";
 #else
-__RCSID("$NetBSD: telnetd.c,v 1.33 2002/08/20 13:58:22 christos Exp $");
+__RCSID("$NetBSD: telnetd.c,v 1.34 2002/09/18 20:58:56 mycroft Exp $");
 #endif
 #endif /* not lint */
 
@@ -1137,7 +1137,7 @@
        (void) ioctl(p, FIONBIO, (char *)&on);
 
 #if    defined(SO_OOBINLINE)
-       (void) setsockopt(net, SOL_SOCKET, SO_OOBINLINE,
+       (void) setsockopt(f, SOL_SOCKET, SO_OOBINLINE,
                                (char *)&on, sizeof on);
 #endif /* defined(SO_OOBINLINE) */
 
@@ -1231,40 +1231,32 @@
 
        nfd = ((f > p) ? f : p) + 1;
        for (;;) {
-               fd_set ibits, obits, xbits;
+               struct pollfd set[2];
                register int c;
 
                if (ncc < 0 && pcc < 0)
                        break;
 
-               FD_ZERO(&ibits);
-               FD_ZERO(&obits);
-               FD_ZERO(&xbits);
-
-               if (f >= FD_SETSIZE)
-                       fatal(net, "fd too large");
-               if (p >= FD_SETSIZE)
-                       fatal(net, "fd too large");
-
                /*
                 * Never look for input if there's still
                 * stuff in the corresponding output buffer
                 */
-               if (nfrontp - nbackp || pcc > 0) {
-                       FD_SET(f, &obits);
-               } else {
-                       FD_SET(p, &ibits);
-               }
-               if (pfrontp - pbackp || ncc > 0) {
-                       FD_SET(p, &obits);
-               } else {
-                       FD_SET(f, &ibits);
-               }
-               if (!SYNCHing) {
-                       FD_SET(f, &xbits);
-               }
-               if ((c = select(nfd, &ibits, &obits, &xbits,
-                                               (struct timeval *)0)) < 1) {
+               set[0].fd = f;
+               set[0].events = 0;
+               set[1].fd = p;
+               set[1].events = 0;
+               if (nfrontp - nbackp || pcc > 0)
+                       set[0].events |= POLLOUT;
+               else
+                       set[1].events |= POLLIN;
+               if (pfrontp - pbackp || ncc > 0)
+                       set[1].events |= POLLOUT;
+               else
+                       set[0].events |= POLLIN;
+               if (!SYNCHing)
+                       set[0].events |= POLLPRI;
+
+               if ((c = poll(set, 2, INFTIM)) < 1) {
                        if (c == -1) {
                                if (errno == EINTR) {
                                        continue;
@@ -1277,14 +1269,14 @@
                /*
                 * Any urgent data?
                 */
-               if (FD_ISSET(net, &xbits)) {
+               if (set[0].revents & POLLPRI) {
                    SYNCHing = 1;
                }
 
                /*
                 * Something to read from the network...
                 */
-               if (FD_ISSET(net, &ibits)) {
+               if (set[0].revents && POLLIN) {
 #if    !defined(SO_OOBINLINE)
                        /*
                         * In 4.2 (and 4.3 beta) systems, the
@@ -1323,24 +1315,24 @@
                    if (SYNCHing) {
                        int atmark;
 
-                       (void) ioctl(net, SIOCATMARK, (char *)&atmark);
+                       (void) ioctl(f, SIOCATMARK, (char *)&atmark);
                        if (atmark) {
-                           ncc = recv(net, netibuf, sizeof (netibuf), MSG_OOB);
+                           ncc = recv(f, netibuf, sizeof (netibuf), MSG_OOB);
                            if ((ncc == -1) && (errno == EINVAL)) {
-                               ncc = read(net, netibuf, sizeof (netibuf));
+                               ncc = read(f, netibuf, sizeof (netibuf));
                                if (sequenceIs(didnetreceive, gotDM)) {
-                                   SYNCHing = stilloob(net);
+                                   SYNCHing = stilloob(f);
                                }
                            }
                        } else {
-                           ncc = read(net, netibuf, sizeof (netibuf));
+                           ncc = read(f, netibuf, sizeof (netibuf));
                        }
                    } else {
-                       ncc = read(net, netibuf, sizeof (netibuf));
+                       ncc = read(f, netibuf, sizeof (netibuf));
                    }
                    settimer(didnetreceive);
 #else  /* !defined(SO_OOBINLINE)) */
-                   ncc = read(net, netibuf, sizeof (netibuf));
+                   ncc = read(f, netibuf, sizeof (netibuf));
 #endif /* !defined(SO_OOBINLINE)) */
                    if (ncc < 0 && errno == EWOULDBLOCK)
                        ncc = 0;
@@ -1358,7 +1350,7 @@
                /*
                 * Something to read from the pty...
                 */
-               if (FD_ISSET(p, &ibits)) {
+               if (set[1].revents & POLLIN) {
 #ifndef        STREAMSPTY
                        pcc = read(p, ptyibuf, BUFSIZ);
 #else
@@ -1443,11 +1435,11 @@
                        }
                }
 
-               if (FD_ISSET(f, &obits) && (nfrontp - nbackp) > 0)
+               if (set[0].revents & POLLOUT && (nfrontp - nbackp) > 0)
                        netflush();
                if (ncc > 0)
                        telrcv();
-               if (FD_ISSET(p, &obits) && (pfrontp - pbackp) > 0)
+               if (set[1].revents & POLLOUT && (pfrontp - pbackp) > 0)
                        ptyflush();
        }
        cleanup(0);
diff -r ee7b3dc4ca88 -r a945fffc34f0 libexec/telnetd/utility.c
--- a/libexec/telnetd/utility.c Wed Sep 18 20:57:02 2002 +0000
+++ b/libexec/telnetd/utility.c Wed Sep 18 20:58:56 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: utility.c,v 1.19 2002/08/12 09:19:00 abs Exp $ */
+/*     $NetBSD: utility.c,v 1.20 2002/09/18 20:58:57 mycroft Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)utility.c  8.4 (Berkeley) 5/30/95";
 #else
-__RCSID("$NetBSD: utility.c,v 1.19 2002/08/12 09:19:00 abs Exp $");
+__RCSID("$NetBSD: utility.c,v 1.20 2002/09/18 20:58:57 mycroft Exp $");
 #endif
 #endif /* not lint */
 
@@ -96,23 +96,19 @@
 stilloob(s)
     int        s;              /* socket number */
 {
-    static struct timeval timeout = { 0 };
-    fd_set     excepts;
+    struct pollfd set[1];
     int value;
 
-    if (s >= FD_SETSIZE)
-       fatal(pty, "fd too large");
-
+    set[0].fd = net;
+    set[0].events = POLLPRI;
     do {
-       FD_ZERO(&excepts);
-       FD_SET(s, &excepts);
-       value = select(s+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout);
+       value = poll(set, 1, 0);
     } while ((value == -1) && (errno == EINTR));
 
     if (value < 0) {
        fatalperror(pty, "select");
     }
-    if (FD_ISSET(s, &excepts)) {
+    if (set[0].revents & POLLPRI) {
        return 1;
     } else {
        return 0;
diff -r ee7b3dc4ca88 -r a945fffc34f0 usr.sbin/apmd/apmd.c
--- a/usr.sbin/apmd/apmd.c      Wed Sep 18 20:57:02 2002 +0000
+++ b/usr.sbin/apmd/apmd.c      Wed Sep 18 20:58:56 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apmd.c,v 1.22 2002/01/11 04:35:52 itojun Exp $ */
+/*     $NetBSD: apmd.c,v 1.23 2002/09/18 21:06:39 mycroft Exp $        */
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -54,6 +54,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/wait.h>
+#include <sys/poll.h>
 #include <machine/apmvar.h>
 #include <err.h>
 #include "pathnames.h"
@@ -309,15 +310,14 @@
     const char *fname = apmdev;
     int ctl_fd, sock_fd, ch, ready;
     int statonly = 0;
-    fd_set devfds;
-    fd_set selcopy;
+    struct pollfd set[2];
     struct apm_event_info apmevent;
     int suspends, standbys, resumes;
     int ac_is_off;
     int noacsleep = 0;
     int lowbattsleep = 0;
     mode_t mode = 0660;
-    struct timeval tv = {TIMO, 0}, stv;
+    unsigned long timeout = TIMO;
     const char *sockname = sockfile;
     char *user, *group;
     char *scratch;
@@ -350,8 +350,8 @@
            sockname = optarg;
            break;
        case 't':
-           tv.tv_sec = strtoul(optarg, 0, 0);
-           if (tv.tv_sec == 0)
+           timeout = strtoul(optarg, 0, 0);
+           if (timeout == 0)
                usage();
            break;
        case 'm':
@@ -427,16 +427,15 @@
 
     sock_fd = bind_socket(sockname, mode, uid, gid);
 
-    FD_ZERO(&devfds);
-    FD_SET(ctl_fd, &devfds);
-    FD_SET(sock_fd, &devfds);
-
+    set[0].fd = ctl_fd;
+    set[0].events = POLLIN;
+    set[1].fd = sock_fd;
+    set[1].events = POLLIN;
 
     
-    for (selcopy = devfds, errno = 0, stv = tv; 
-        (ready = select(MAX(ctl_fd,sock_fd)+1, &selcopy, 0, 0, &stv)) >= 0 ||
-            errno == EINTR;
-        selcopy = devfds, errno = 0, stv = tv) {
+    for (errno = 0;
+        (ready = poll(set, 2, timeout * 1000)) >= 0 || errno == EINTR;
+        errno = 0) {
        if (errno == EINTR)
            continue;
        if (ready == 0) {
@@ -453,7 +452,7 @@
                                suspend(ctl_fd);
                }
        }
-       if (FD_ISSET(ctl_fd, &selcopy)) {
+       if (set[0].revents & POLLIN) {
            suspends = standbys = resumes = 0;
            while (ioctl(ctl_fd, APM_IOC_NEXTEVENT, &apmevent) == 0) {
                if (debug)



Home | Main Index | Thread Index | Old Index