Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec select() -> poll()
details: https://anonhg.NetBSD.org/src/rev/019dab83c533
branches: trunk
changeset: 536571:019dab83c533
user: mycroft <mycroft%NetBSD.org@localhost>
date: Wed Sep 18 20:37:11 2002 +0000
description:
select() -> poll()
diffstat:
libexec/rlogind/rlogind.c | 73 ++++++++++++++++------------------------------
libexec/rshd/rshd.c | 36 +++++++++-------------
2 files changed, 41 insertions(+), 68 deletions(-)
diffs (247 lines):
diff -r 572c7466b88b -r 019dab83c533 libexec/rlogind/rlogind.c
--- a/libexec/rlogind/rlogind.c Wed Sep 18 20:20:28 2002 +0000
+++ b/libexec/rlogind/rlogind.c Wed Sep 18 20:37:11 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rlogind.c,v 1.26 2002/08/20 13:14:41 christos Exp $ */
+/* $NetBSD: rlogind.c,v 1.27 2002/09/18 20:37:11 mycroft Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@@ -73,7 +73,7 @@
#if 0
static char sccsid[] = "@(#)rlogind.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: rlogind.c,v 1.26 2002/08/20 13:14:41 christos Exp $");
+__RCSID("$NetBSD: rlogind.c,v 1.27 2002/09/18 20:37:11 mycroft Exp $");
#endif
#endif /* not lint */
@@ -86,10 +86,10 @@
* data
*/
-#define FD_SETSIZE 16 /* don't need many bits for select */
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+#include <sys/poll.h>
#include <signal.h>
#include <termios.h>
@@ -474,34 +474,27 @@
nfd = f + 1;
else
nfd = p + 1;
- if (nfd > FD_SETSIZE) {
- syslog(LOG_ERR, "select mask too small, increase FD_SETSIZE");
- fatal(f, "internal error (select mask too small)", 0);
- }
for (;;) {
- fd_set ibits, obits, ebits, *omask;
+ struct pollfd set[2];
- FD_ZERO(&ebits);
- FD_ZERO(&ibits);
- FD_ZERO(&obits);
- omask = (fd_set *)NULL;
- if (fcc) {
- FD_SET(p, &obits);
- omask = &obits;
- } else
- FD_SET(f, &ibits);
+ set[0].fd = p;
+ set[0].events = POLLPRI;
+ set[1].fd = f;
+ set[1].events = 0;
+ if (fcc)
+ set[0].events |= POLLOUT;
+ else
+ set[1].events |= POLLIN;
if (pcc >= 0) {
- if (pcc) {
- FD_SET(f, &obits);
- omask = &obits;
- } else
- FD_SET(p, &ibits);
+ if (pcc)
+ set[1].events |= POLLOUT;
+ else
+ set[0].events |= POLLIN;
}
- FD_SET(p, &ebits);
- if ((n = select(nfd, &ibits, omask, &ebits, 0)) < 0) {
+ if ((n = poll(set, 2, INFTIM)) < 0) {
if (errno == EINTR)
continue;
- fatal(f, "select", 1);
+ fatal(f, "poll", 1);
}
if (n == 0) {
/* shouldn't happen... */
@@ -509,19 +502,17 @@
continue;
}
#define pkcontrol(c) ((c)&(TIOCPKT_FLUSHWRITE|TIOCPKT_NOSTOP|TIOCPKT_DOSTOP))
- if (FD_ISSET(p, &ebits)) {
+ if (set[0].revents & POLLPRI) {
cc = read(p, &cntl, 1);
if (cc == 1 && pkcontrol(cntl)) {
cntl |= oobdata[0];
send(f, &cntl, 1, MSG_OOB);
- if (cntl & TIOCPKT_FLUSHWRITE) {
+ if (cntl & TIOCPKT_FLUSHWRITE)
pcc = 0;
- FD_CLR(p, &ibits);
- }
}
}
- if (FD_ISSET(f, &ibits)) {
- fcc = read(f, fibuf, sizeof(fibuf));
+ if (set[1].revents & POLLIN) {
+ fcc = read(f, fibuf, sizeof(fibuf));
if (fcc < 0 && errno == EWOULDBLOCK)
fcc = 0;
else {
@@ -548,11 +539,10 @@
goto top; /* n^2 */
}
}
- FD_SET(p, &obits); /* try write */
}
}
- if (FD_ISSET(p, &obits) && fcc > 0) {
+ if (set[0].revents & POLLOUT && fcc > 0) {
cc = write(p, fbp, fcc);
if (cc > 0) {
fcc -= cc;
@@ -560,7 +550,7 @@
}
}
- if (FD_ISSET(p, &ibits)) {
+ if (set[0].revents & POLLIN) {
pcc = read(p, pibuf, sizeof (pibuf));
pbp = pibuf;
if (pcc < 0 && errno == EWOULDBLOCK)
@@ -569,7 +559,6 @@
break;
else if (pibuf[0] == 0) {
pbp++, pcc--;
- FD_SET(f, &obits); /* try write */
} else {
if (pkcontrol(pibuf[0])) {
pibuf[0] |= oobdata[0];
@@ -578,18 +567,8 @@
pcc = 0;
}
}
- if ((FD_ISSET(f, &obits)) && pcc > 0) {
- cc = write(f, pbp, pcc);
- if (cc < 0 && errno == EWOULDBLOCK) {
- /*
- * This happens when we try write after read
- * from p, but some old kernels balk at large
- * writes even when select returns true.
- */
- if (!FD_ISSET(p, &ibits))
- sleep(5);
- continue;
- }
+ if (set[1].revents & POLLOUT && pcc > 0) {
+ cc = write(f, pbp, pcc);
if (cc > 0) {
pcc -= cc;
pbp += cc;
diff -r 572c7466b88b -r 019dab83c533 libexec/rshd/rshd.c
--- a/libexec/rshd/rshd.c Wed Sep 18 20:20:28 2002 +0000
+++ b/libexec/rshd/rshd.c Wed Sep 18 20:37:11 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rshd.c,v 1.25 2002/03/18 23:59:57 mjl Exp $ */
+/* $NetBSD: rshd.c,v 1.26 2002/09/18 20:44:38 mycroft Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@@ -73,7 +73,7 @@
#if 0
static char sccsid[] = "@(#)rshd.c 8.2 (Berkeley) 4/6/94";
#else
-__RCSID("$NetBSD: rshd.c,v 1.25 2002/03/18 23:59:57 mjl Exp $");
+__RCSID("$NetBSD: rshd.c,v 1.26 2002/09/18 20:44:38 mycroft Exp $");
#endif
#endif /* not lint */
@@ -89,6 +89,7 @@
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/socket.h>
+#include <sys/poll.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -224,8 +225,8 @@
{
struct passwd *pwd;
in_port_t port;
- fd_set ready, readfrom;
- int cc, nfd, pv[2], pid, s = -1; /* XXX gcc */
+ struct pollfd set[2];
+ int cc, pv[2], pid, s = -1; /* XXX gcc */
int one = 1;
char *hostname, *errorstr, *errorhost = NULL; /* XXX gcc */
const char *cp;
@@ -508,44 +509,37 @@
(void) close(2);
(void) close(pv[1]);
- FD_ZERO(&readfrom);
- FD_SET(s, &readfrom);
- FD_SET(pv[0], &readfrom);
- if (pv[0] > s)
- nfd = pv[0];
- else
- nfd = s;
+ set[0].fd = s;
+ set[0].events = POLLIN;
+ set[1].fd = pv[0];
+ set[1].events = POLLIN;
ioctl(pv[0], FIONBIO, (char *)&one);
/* should set s nbio! */
- nfd++;
do {
- ready = readfrom;
- if (select(nfd, &ready, (fd_set *)0,
- (fd_set *)0, (struct timeval *)0) < 0)
+ if (poll(set, 2, INFTIM) < 0)
break;
- if (FD_ISSET(s, &ready)) {
+ if (set[0].revents & POLLIN) {
int ret;
ret = read(s, &sig, 1);
if (ret <= 0)
- FD_CLR(s, &readfrom);
+ set[0].events = 0;
else
killpg(pid, sig);
}
- if (FD_ISSET(pv[0], &ready)) {
+ if (set[1].revents & POLLIN) {
errno = 0;
cc = read(pv[0], buf, sizeof(buf));
if (cc <= 0) {
shutdown(s, SHUT_RDWR);
- FD_CLR(pv[0], &readfrom);
+ set[1].events = 0;
} else {
(void) write(s, buf, cc);
}
}
- } while (FD_ISSET(s, &readfrom) ||
- FD_ISSET(pv[0], &readfrom));
+ } while ((set[0].revents | set[1].revents) & POLLIN);
exit(0);
}
setpgrp(0, getpid());
Home |
Main Index |
Thread Index |
Old Index