select() -> poll()
This commit is contained in:
parent
f90ffa1f0c
commit
e92308f210
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: hunt.c,v 1.12 2001/02/05 00:40:45 christos Exp $ */
|
||||
/* $NetBSD: hunt.c,v 1.13 2002/09/20 15:47:19 mycroft Exp $ */
|
||||
/*
|
||||
* Hunt
|
||||
* Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
|
||||
@ -7,12 +7,13 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: hunt.c,v 1.12 2001/02/05 00:40:45 christos Exp $");
|
||||
__RCSID("$NetBSD: hunt.c,v 1.13 2002/09/20 15:47:19 mycroft Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
# include <sys/param.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/time.h>
|
||||
# include <sys/poll.h>
|
||||
# include <ctype.h>
|
||||
# include <err.h>
|
||||
# include <errno.h>
|
||||
@ -398,8 +399,7 @@ list_drivers()
|
||||
static SOCKET *listv;
|
||||
static unsigned int listmax;
|
||||
unsigned int listc;
|
||||
fd_set mask;
|
||||
struct timeval wait;
|
||||
struct pollfd set[1];
|
||||
|
||||
if (initial) { /* do one time initialization */
|
||||
# ifndef BROADCAST
|
||||
@ -497,8 +497,8 @@ list_drivers()
|
||||
get_response:
|
||||
namelen = DAEMON_SIZE;
|
||||
errno = 0;
|
||||
wait.tv_sec = 1;
|
||||
wait.tv_usec = 0;
|
||||
set[0].fd = test_socket;
|
||||
set[0].events = POLLIN;
|
||||
for (;;) {
|
||||
if (listc + 1 >= listmax) {
|
||||
listmax += 20;
|
||||
@ -506,9 +506,7 @@ get_response:
|
||||
listmax * sizeof(SOCKET));
|
||||
}
|
||||
|
||||
FD_ZERO(&mask);
|
||||
FD_SET(test_socket, &mask);
|
||||
if (select(test_socket + 1, &mask, NULL, NULL, &wait) == 1 &&
|
||||
if (poll(set, 1, 1000) == 1 &&
|
||||
recvfrom(test_socket, (char *) &port_num, sizeof(port_num),
|
||||
0, (struct sockaddr *) &listv[listc], &namelen) > 0) {
|
||||
/*
|
||||
@ -526,8 +524,8 @@ get_response:
|
||||
}
|
||||
|
||||
if (errno != 0 && errno != EINTR) {
|
||||
warn("select/recvfrom");
|
||||
leave(1, "select/recvfrom");
|
||||
warn("poll/recvfrom");
|
||||
leave(1, "poll/recvfrom");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: playit.c,v 1.4 1997/10/20 00:37:15 lukem Exp $ */
|
||||
/* $NetBSD: playit.c,v 1.5 2002/09/20 15:47:19 mycroft Exp $ */
|
||||
/*
|
||||
* Hunt
|
||||
* Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
|
||||
@ -7,10 +7,11 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: playit.c,v 1.4 1997/10/20 00:37:15 lukem Exp $");
|
||||
__RCSID("$NetBSD: playit.c,v 1.5 2002/09/20 15:47:19 mycroft Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
# include <sys/file.h>
|
||||
# include <sys/poll.h>
|
||||
# include <err.h>
|
||||
# include <errno.h>
|
||||
# include <curses.h>
|
||||
@ -217,26 +218,23 @@ out:
|
||||
static unsigned char
|
||||
getchr()
|
||||
{
|
||||
fd_set readfds, s_readfds;
|
||||
int nfds, s_nfds;
|
||||
struct pollfd set[2];
|
||||
int nfds;
|
||||
|
||||
FD_ZERO(&s_readfds);
|
||||
FD_SET(Socket, &s_readfds);
|
||||
FD_SET(STDIN, &s_readfds);
|
||||
s_nfds = (Socket > STDIN) ? Socket : STDIN;
|
||||
s_nfds++;
|
||||
set[0].fd = Socket;
|
||||
set[0].events = POLLIN;
|
||||
set[1].fd = STDIN;
|
||||
set[1].events = POLLIN;
|
||||
|
||||
one_more_time:
|
||||
do {
|
||||
errno = 0;
|
||||
readfds = s_readfds;
|
||||
nfds = s_nfds;
|
||||
nfds = select(nfds, &readfds, NULL, NULL, NULL);
|
||||
nfds = poll(set, 2, INFTIM);
|
||||
} while (nfds <= 0 && errno == EINTR);
|
||||
|
||||
if (FD_ISSET(STDIN, &readfds))
|
||||
if (set[1].revents && POLLIN)
|
||||
send_stuff();
|
||||
if (! FD_ISSET(Socket, &readfds))
|
||||
if (! (set[0].revents & POLLIN))
|
||||
goto one_more_time;
|
||||
icnt = read(Socket, ibuf, sizeof ibuf);
|
||||
if (icnt < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user