select() -> poll()

This commit is contained in:
mycroft 2002-09-18 23:13:39 +00:00
parent 4fa2032edc
commit c563d4c7c3
3 changed files with 48 additions and 51 deletions

View File

@ -22,7 +22,7 @@ SOFTWARE.
#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 @@ __RCSID("$NetBSD: bootpd.c,v 1.14 2002/07/13 23:56:39 wiz Exp $");
#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 @@ struct sockaddr_in send_addr; /* destination */
* 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 @@ char *bootpd_dump = DUMPTAB_FILE;
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 @@ main(int argc, char **argv)
* Set defaults that might be changed by option switches.
*/
stmp = NULL;
timeout = &actualtimeout;
timeout = actualtimeout;
/*
* Read switches.
@ -333,13 +331,13 @@ main(int argc, char **argv)
"%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 @@ main(int argc, char **argv)
/*
* Nuke any timeout value
*/
timeout = NULL;
timeout = INFTIM;
} /* if standalone (1st) */
@ -488,12 +486,13 @@ main(int argc, char **argv)
/*
* 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 @@ main(int argc, char **argv)
}
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);

View File

@ -27,7 +27,7 @@ SOFTWARE.
#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 @@ __RCSID("$NetBSD: bootpgw.c,v 1.9 2002/07/13 23:59:45 wiz Exp $");
#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 @@ struct sockaddr_in serv_addr; /* server address */
* 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 @@ struct in_addr my_ip_addr;
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 @@ main(int argc, char **argv)
* 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 @@ main(int argc, char **argv)
"%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 @@ main(int argc, char **argv)
/*
* Nuke any timeout value
*/
timeout = NULL;
timeout = INFTIM;
/*
* Here, bootpd would do:
@ -431,18 +429,19 @@ main(int argc, char **argv)
/*
* 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);

View File

@ -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 @@ char *usage = "bootptest [-h] server-name [vendor-data-template-file]";
#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 @@ main(int argc, char **argv)
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) {