diff options
author | ume <ume@FreeBSD.org> | 2003-08-18 15:35:33 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2003-08-18 15:35:33 +0000 |
commit | 305bef8b9ab99ac2f80832cfa9a81ab3cd4eb2b8 (patch) | |
tree | 8ef6a5f14a48f40fd7206e5a92e9c4049aa57de7 | |
parent | 3dfab70e236e5864b7730ef23011246df9a692f6 (diff) | |
download | FreeBSD-src-305bef8b9ab99ac2f80832cfa9a81ab3cd4eb2b8.zip FreeBSD-src-305bef8b9ab99ac2f80832cfa9a81ab3cd4eb2b8.tar.gz |
support poll(2).
Obtained from: KAME
MFC after: 1 week
-rw-r--r-- | usr.sbin/route6d/Makefile | 2 | ||||
-rw-r--r-- | usr.sbin/route6d/route6d.c | 47 |
2 files changed, 44 insertions, 5 deletions
diff --git a/usr.sbin/route6d/Makefile b/usr.sbin/route6d/Makefile index f1293f6..1bed21a 100644 --- a/usr.sbin/route6d/Makefile +++ b/usr.sbin/route6d/Makefile @@ -4,6 +4,6 @@ PROG= route6d MAN= route6d.8 -CFLAGS+= -DINET6 +CFLAGS+= -DINET6 -DHAVE_POLL_H .include <bsd.prog.mk> diff --git a/usr.sbin/route6d/route6d.c b/usr.sbin/route6d/route6d.c index bb646c3..904c0bc 100644 --- a/usr.sbin/route6d/route6d.c +++ b/usr.sbin/route6d/route6d.c @@ -50,6 +50,9 @@ static char _rcsid[] = "$KAME: route6d.c,v 1.64 2001/05/08 04:36:37 itojun Exp $ #include <stddef.h> #include <errno.h> #include <err.h> +#ifdef HAVE_POLL_H +#include <poll.h> +#endif #include <sys/types.h> #include <sys/param.h> @@ -138,10 +141,14 @@ int nifc; /* number of valid ifc's */ struct ifc **index2ifc; int nindex2ifc; struct ifc *loopifcp = NULL; /* pointing to loopback */ +#ifdef HAVE_POLL_H +struct pollfd set[2]; +#else fd_set *sockvecp; /* vector to select() for receiving */ fd_set *recvecp; int fdmasks; int maxfd; /* maximum fd for select() */ +#endif int rtsock; /* the routing socket */ int ripsock; /* socket to send/receive RIP datagram */ @@ -458,8 +465,13 @@ main(argc, argv) } signo = 0; +#ifdef HAVE_POLL_H + switch (poll(set, 2, INFTIM)) +#else memcpy(recvecp, sockvecp, fdmasks); - switch (select(maxfd + 1, recvecp, 0, 0, 0)) { + switch (select(maxfd + 1, recvecp, 0, 0, 0)) +#endif + { case -1: if (errno != EINTR) { fatal("select"); @@ -469,12 +481,22 @@ main(argc, argv) case 0: continue; default: - if (FD_ISSET(ripsock, recvecp)) { +#ifdef HAVE_POLL_H + if (set[0].revents & POLLIN) +#else + if (FD_ISSET(ripsock, recvecp)) +#endif + { sigprocmask(SIG_BLOCK, &mask, &omask); riprecv(); sigprocmask(SIG_SETMASK, &omask, NULL); } - if (FD_ISSET(rtsock, recvecp)) { +#ifdef HAVE_POLL_H + if (set[1].revents & POLLIN) +#else + if (FD_ISSET(rtsock, recvecp)) +#endif + { sigprocmask(SIG_BLOCK, &mask, &omask); rtrecv(); sigprocmask(SIG_SETMASK, &omask, NULL); @@ -659,18 +681,34 @@ init() } memcpy(&ripsin, res->ai_addr, res->ai_addrlen); +#ifdef HAVE_POLL_H + set[0].fd = ripsock; + set[0].events = POLLIN; +#else maxfd = ripsock; +#endif if (nflag == 0) { if ((rtsock = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) { fatal("route socket"); /*NOTREACHED*/ } +#ifdef HAVE_POLL_H + set[1].fd = rtsock; + set[1].events = POLLIN; +#else if (rtsock > maxfd) maxfd = rtsock; - } else +#endif + } else { +#ifdef HAVE_POLL_H + set[1].fd = -1; +#else rtsock = -1; /*just for safety */ +#endif + } +#ifndef HAVE_POLL_H fdmasks = howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask); if ((sockvecp = malloc(fdmasks)) == NULL) { fatal("malloc"); @@ -684,6 +722,7 @@ init() FD_SET(ripsock, sockvecp); if (rtsock >= 0) FD_SET(rtsock, sockvecp); +#endif } #define RIPSIZE(n) \ |