From 016f9036427c9e071d230ca0ff75bbe4b228fa83 Mon Sep 17 00:00:00 2001 From: mycroft Date: Fri, 20 Sep 2002 21:48:58 +0000 Subject: [PATCH] select() -> poll() --- crypto/dist/heimdal/lib/roken/mini_inetd.c | 36 ++++++++++++++++++++-- crypto/dist/heimdal/lib/roken/roken.h.in | 5 ++- include/heimdal/roken.h | 5 ++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/crypto/dist/heimdal/lib/roken/mini_inetd.c b/crypto/dist/heimdal/lib/roken/mini_inetd.c index a455d15c4bfd..a4149e49f63f 100644 --- a/crypto/dist/heimdal/lib/roken/mini_inetd.c +++ b/crypto/dist/heimdal/lib/roken/mini_inetd.c @@ -34,7 +34,7 @@ #ifdef HAVE_CONFIG_H #include __RCSID("$Heimdal: mini_inetd.c,v 1.30 2002/02/18 19:08:55 joda Exp $" - "$NetBSD: mini_inetd.c,v 1.1.1.5 2002/09/12 12:41:42 joda Exp $"); + "$NetBSD: mini_inetd.c,v 1.2 2002/09/20 21:48:58 mycroft Exp $"); #endif #include @@ -70,8 +70,12 @@ mini_inetd_addrinfo (struct addrinfo *ai) struct addrinfo *a; int n, nalloc, i; int *fds; +#ifdef HAVE_POLL + struct pollfd *set; +#else fd_set orig_read_set, read_set; int max_fd = -1; +#endif for (nalloc = 0, a = ai; a != NULL; a = a->ai_next) ++nalloc; @@ -80,7 +84,13 @@ mini_inetd_addrinfo (struct addrinfo *ai) if (fds == NULL) errx (1, "mini_inetd: out of memory"); +#ifdef HAVE_POLL + set = malloc (nalloc * sizeof(*set)); + if (set == NULL) + errx (1, "mini_inetd: out of memory"); +#else FD_ZERO(&orig_read_set); +#endif for (i = 0, a = ai; a != NULL; a = a->ai_next) { fds[i] = socket (a->ai_family, a->ai_socktype, a->ai_protocol); @@ -99,10 +109,15 @@ mini_inetd_addrinfo (struct addrinfo *ai) close(fds[i]); continue; } +#ifdef HAVE_POLL + set[i].fd = fds[i]; + set[i].events = POLLIN; +#else if (fds[i] >= FD_SETSIZE) errx (1, "fd too large"); FD_SET(fds[i], &orig_read_set); max_fd = max(max_fd, fds[i]); +#endif ++i; } if (i == 0) @@ -110,16 +125,33 @@ mini_inetd_addrinfo (struct addrinfo *ai) n = i; do { +#ifdef HAVE_POLL + ret = poll (set, nalloc, INFTIM); +#else read_set = orig_read_set; ret = select (max_fd + 1, &read_set, NULL, NULL, NULL); +#endif if (ret < 0 && errno != EINTR) +#ifdef HAVE_POLL + err (1, "poll"); +#else err (1, "select"); +#endif } while (ret <= 0); for (i = 0; i < n; ++i) - if (FD_ISSET (fds[i], &read_set)) { +#ifdef HAVE_POLL + if (set[i].revents & POLLIN) +#else + if (FD_ISSET (fds[i], &read_set)) +#endif + { accept_it (fds[i]); + free (fds); +#ifdef HAVE_POLL + free (set); +#endif return; } abort (); diff --git a/crypto/dist/heimdal/lib/roken/roken.h.in b/crypto/dist/heimdal/lib/roken/roken.h.in index aa2a64f876d4..a58be2e46501 100644 --- a/crypto/dist/heimdal/lib/roken/roken.h.in +++ b/crypto/dist/heimdal/lib/roken/roken.h.in @@ -33,7 +33,7 @@ */ /* $Heimdal: roken.h.in,v 1.169 2002/08/26 21:43:38 assar Exp $ - $NetBSD: roken.h.in,v 1.1.1.6 2002/09/12 12:41:42 joda Exp $ */ + $NetBSD: roken.h.in,v 1.2 2002/09/20 21:48:58 mycroft Exp $ */ #include #include @@ -125,6 +125,9 @@ struct sockaddr_dl; #else #include #endif +#ifdef HAVE_SYS_POLL_H +#include +#endif #ifdef HAVE_PATHS_H #include diff --git a/include/heimdal/roken.h b/include/heimdal/roken.h index 8c8cb774d255..95ebfb118787 100644 --- a/include/heimdal/roken.h +++ b/include/heimdal/roken.h @@ -39,7 +39,7 @@ */ /* $Heimdal: roken.h.in,v 1.169 2002/08/26 21:43:38 assar Exp $ - $NetBSD: roken.h,v 1.7 2002/09/12 13:32:38 joda Exp $ */ + $NetBSD: roken.h,v 1.8 2002/09/20 21:48:59 mycroft Exp $ */ #include #include @@ -68,6 +68,9 @@ #include #include #include +#ifdef HAVE_SYS_POLL_H +#include +#endif #include