select() -> poll()
This commit is contained in:
parent
4243014e02
commit
720a68f0ca
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: defs.h,v 1.11 2002/05/26 00:02:08 wiz Exp $ */
|
/* $NetBSD: defs.h,v 1.12 2002/09/18 20:58:56 mycroft Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993
|
* Copyright (c) 1989, 1993
|
||||||
@ -72,6 +72,7 @@
|
|||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <sys/poll.h>
|
||||||
#ifndef FILIO_H
|
#ifndef FILIO_H
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#else
|
#else
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: telnetd.c,v 1.33 2002/08/20 13:58:22 christos Exp $ */
|
/* $NetBSD: telnetd.c,v 1.34 2002/09/18 20:58:56 mycroft Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 1997 and 1998 WIDE Project.
|
* Copyright (C) 1997 and 1998 WIDE Project.
|
||||||
@ -69,7 +69,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95";
|
static char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: telnetd.c,v 1.33 2002/08/20 13:58:22 christos Exp $");
|
__RCSID("$NetBSD: telnetd.c,v 1.34 2002/09/18 20:58:56 mycroft Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -1137,7 +1137,7 @@ telnet(f, p, host)
|
|||||||
(void) ioctl(p, FIONBIO, (char *)&on);
|
(void) ioctl(p, FIONBIO, (char *)&on);
|
||||||
|
|
||||||
#if defined(SO_OOBINLINE)
|
#if defined(SO_OOBINLINE)
|
||||||
(void) setsockopt(net, SOL_SOCKET, SO_OOBINLINE,
|
(void) setsockopt(f, SOL_SOCKET, SO_OOBINLINE,
|
||||||
(char *)&on, sizeof on);
|
(char *)&on, sizeof on);
|
||||||
#endif /* defined(SO_OOBINLINE) */
|
#endif /* defined(SO_OOBINLINE) */
|
||||||
|
|
||||||
@ -1231,40 +1231,32 @@ telnet(f, p, host)
|
|||||||
|
|
||||||
nfd = ((f > p) ? f : p) + 1;
|
nfd = ((f > p) ? f : p) + 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
fd_set ibits, obits, xbits;
|
struct pollfd set[2];
|
||||||
register int c;
|
register int c;
|
||||||
|
|
||||||
if (ncc < 0 && pcc < 0)
|
if (ncc < 0 && pcc < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
FD_ZERO(&ibits);
|
|
||||||
FD_ZERO(&obits);
|
|
||||||
FD_ZERO(&xbits);
|
|
||||||
|
|
||||||
if (f >= FD_SETSIZE)
|
|
||||||
fatal(net, "fd too large");
|
|
||||||
if (p >= FD_SETSIZE)
|
|
||||||
fatal(net, "fd too large");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Never look for input if there's still
|
* Never look for input if there's still
|
||||||
* stuff in the corresponding output buffer
|
* stuff in the corresponding output buffer
|
||||||
*/
|
*/
|
||||||
if (nfrontp - nbackp || pcc > 0) {
|
set[0].fd = f;
|
||||||
FD_SET(f, &obits);
|
set[0].events = 0;
|
||||||
} else {
|
set[1].fd = p;
|
||||||
FD_SET(p, &ibits);
|
set[1].events = 0;
|
||||||
}
|
if (nfrontp - nbackp || pcc > 0)
|
||||||
if (pfrontp - pbackp || ncc > 0) {
|
set[0].events |= POLLOUT;
|
||||||
FD_SET(p, &obits);
|
else
|
||||||
} else {
|
set[1].events |= POLLIN;
|
||||||
FD_SET(f, &ibits);
|
if (pfrontp - pbackp || ncc > 0)
|
||||||
}
|
set[1].events |= POLLOUT;
|
||||||
if (!SYNCHing) {
|
else
|
||||||
FD_SET(f, &xbits);
|
set[0].events |= POLLIN;
|
||||||
}
|
if (!SYNCHing)
|
||||||
if ((c = select(nfd, &ibits, &obits, &xbits,
|
set[0].events |= POLLPRI;
|
||||||
(struct timeval *)0)) < 1) {
|
|
||||||
|
if ((c = poll(set, 2, INFTIM)) < 1) {
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
continue;
|
continue;
|
||||||
@ -1277,14 +1269,14 @@ telnet(f, p, host)
|
|||||||
/*
|
/*
|
||||||
* Any urgent data?
|
* Any urgent data?
|
||||||
*/
|
*/
|
||||||
if (FD_ISSET(net, &xbits)) {
|
if (set[0].revents & POLLPRI) {
|
||||||
SYNCHing = 1;
|
SYNCHing = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Something to read from the network...
|
* Something to read from the network...
|
||||||
*/
|
*/
|
||||||
if (FD_ISSET(net, &ibits)) {
|
if (set[0].revents && POLLIN) {
|
||||||
#if !defined(SO_OOBINLINE)
|
#if !defined(SO_OOBINLINE)
|
||||||
/*
|
/*
|
||||||
* In 4.2 (and 4.3 beta) systems, the
|
* In 4.2 (and 4.3 beta) systems, the
|
||||||
@ -1323,24 +1315,24 @@ telnet(f, p, host)
|
|||||||
if (SYNCHing) {
|
if (SYNCHing) {
|
||||||
int atmark;
|
int atmark;
|
||||||
|
|
||||||
(void) ioctl(net, SIOCATMARK, (char *)&atmark);
|
(void) ioctl(f, SIOCATMARK, (char *)&atmark);
|
||||||
if (atmark) {
|
if (atmark) {
|
||||||
ncc = recv(net, netibuf, sizeof (netibuf), MSG_OOB);
|
ncc = recv(f, netibuf, sizeof (netibuf), MSG_OOB);
|
||||||
if ((ncc == -1) && (errno == EINVAL)) {
|
if ((ncc == -1) && (errno == EINVAL)) {
|
||||||
ncc = read(net, netibuf, sizeof (netibuf));
|
ncc = read(f, netibuf, sizeof (netibuf));
|
||||||
if (sequenceIs(didnetreceive, gotDM)) {
|
if (sequenceIs(didnetreceive, gotDM)) {
|
||||||
SYNCHing = stilloob(net);
|
SYNCHing = stilloob(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ncc = read(net, netibuf, sizeof (netibuf));
|
ncc = read(f, netibuf, sizeof (netibuf));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ncc = read(net, netibuf, sizeof (netibuf));
|
ncc = read(f, netibuf, sizeof (netibuf));
|
||||||
}
|
}
|
||||||
settimer(didnetreceive);
|
settimer(didnetreceive);
|
||||||
#else /* !defined(SO_OOBINLINE)) */
|
#else /* !defined(SO_OOBINLINE)) */
|
||||||
ncc = read(net, netibuf, sizeof (netibuf));
|
ncc = read(f, netibuf, sizeof (netibuf));
|
||||||
#endif /* !defined(SO_OOBINLINE)) */
|
#endif /* !defined(SO_OOBINLINE)) */
|
||||||
if (ncc < 0 && errno == EWOULDBLOCK)
|
if (ncc < 0 && errno == EWOULDBLOCK)
|
||||||
ncc = 0;
|
ncc = 0;
|
||||||
@ -1358,7 +1350,7 @@ telnet(f, p, host)
|
|||||||
/*
|
/*
|
||||||
* Something to read from the pty...
|
* Something to read from the pty...
|
||||||
*/
|
*/
|
||||||
if (FD_ISSET(p, &ibits)) {
|
if (set[1].revents & POLLIN) {
|
||||||
#ifndef STREAMSPTY
|
#ifndef STREAMSPTY
|
||||||
pcc = read(p, ptyibuf, BUFSIZ);
|
pcc = read(p, ptyibuf, BUFSIZ);
|
||||||
#else
|
#else
|
||||||
@ -1443,11 +1435,11 @@ telnet(f, p, host)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(f, &obits) && (nfrontp - nbackp) > 0)
|
if (set[0].revents & POLLOUT && (nfrontp - nbackp) > 0)
|
||||||
netflush();
|
netflush();
|
||||||
if (ncc > 0)
|
if (ncc > 0)
|
||||||
telrcv();
|
telrcv();
|
||||||
if (FD_ISSET(p, &obits) && (pfrontp - pbackp) > 0)
|
if (set[1].revents & POLLOUT && (pfrontp - pbackp) > 0)
|
||||||
ptyflush();
|
ptyflush();
|
||||||
}
|
}
|
||||||
cleanup(0);
|
cleanup(0);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: utility.c,v 1.19 2002/08/12 09:19:00 abs Exp $ */
|
/* $NetBSD: utility.c,v 1.20 2002/09/18 20:58:57 mycroft Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993
|
* Copyright (c) 1989, 1993
|
||||||
@ -38,7 +38,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95";
|
static char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: utility.c,v 1.19 2002/08/12 09:19:00 abs Exp $");
|
__RCSID("$NetBSD: utility.c,v 1.20 2002/09/18 20:58:57 mycroft Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -96,23 +96,19 @@ ttloop()
|
|||||||
stilloob(s)
|
stilloob(s)
|
||||||
int s; /* socket number */
|
int s; /* socket number */
|
||||||
{
|
{
|
||||||
static struct timeval timeout = { 0 };
|
struct pollfd set[1];
|
||||||
fd_set excepts;
|
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
if (s >= FD_SETSIZE)
|
set[0].fd = net;
|
||||||
fatal(pty, "fd too large");
|
set[0].events = POLLPRI;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
FD_ZERO(&excepts);
|
value = poll(set, 1, 0);
|
||||||
FD_SET(s, &excepts);
|
|
||||||
value = select(s+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout);
|
|
||||||
} while ((value == -1) && (errno == EINTR));
|
} while ((value == -1) && (errno == EINTR));
|
||||||
|
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
fatalperror(pty, "select");
|
fatalperror(pty, "select");
|
||||||
}
|
}
|
||||||
if (FD_ISSET(s, &excepts)) {
|
if (set[0].revents & POLLPRI) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: apmd.c,v 1.22 2002/01/11 04:35:52 itojun Exp $ */
|
/* $NetBSD: apmd.c,v 1.23 2002/09/18 21:06:39 mycroft Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
|
* Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
|
||||||
@ -54,6 +54,7 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/poll.h>
|
||||||
#include <machine/apmvar.h>
|
#include <machine/apmvar.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
@ -309,15 +310,14 @@ main(int argc, char *argv[])
|
|||||||
const char *fname = apmdev;
|
const char *fname = apmdev;
|
||||||
int ctl_fd, sock_fd, ch, ready;
|
int ctl_fd, sock_fd, ch, ready;
|
||||||
int statonly = 0;
|
int statonly = 0;
|
||||||
fd_set devfds;
|
struct pollfd set[2];
|
||||||
fd_set selcopy;
|
|
||||||
struct apm_event_info apmevent;
|
struct apm_event_info apmevent;
|
||||||
int suspends, standbys, resumes;
|
int suspends, standbys, resumes;
|
||||||
int ac_is_off;
|
int ac_is_off;
|
||||||
int noacsleep = 0;
|
int noacsleep = 0;
|
||||||
int lowbattsleep = 0;
|
int lowbattsleep = 0;
|
||||||
mode_t mode = 0660;
|
mode_t mode = 0660;
|
||||||
struct timeval tv = {TIMO, 0}, stv;
|
unsigned long timeout = TIMO;
|
||||||
const char *sockname = sockfile;
|
const char *sockname = sockfile;
|
||||||
char *user, *group;
|
char *user, *group;
|
||||||
char *scratch;
|
char *scratch;
|
||||||
@ -350,8 +350,8 @@ main(int argc, char *argv[])
|
|||||||
sockname = optarg;
|
sockname = optarg;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
tv.tv_sec = strtoul(optarg, 0, 0);
|
timeout = strtoul(optarg, 0, 0);
|
||||||
if (tv.tv_sec == 0)
|
if (timeout == 0)
|
||||||
usage();
|
usage();
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
@ -427,16 +427,15 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
sock_fd = bind_socket(sockname, mode, uid, gid);
|
sock_fd = bind_socket(sockname, mode, uid, gid);
|
||||||
|
|
||||||
FD_ZERO(&devfds);
|
set[0].fd = ctl_fd;
|
||||||
FD_SET(ctl_fd, &devfds);
|
set[0].events = POLLIN;
|
||||||
FD_SET(sock_fd, &devfds);
|
set[1].fd = sock_fd;
|
||||||
|
set[1].events = POLLIN;
|
||||||
|
|
||||||
|
|
||||||
for (selcopy = devfds, errno = 0, stv = tv;
|
for (errno = 0;
|
||||||
(ready = select(MAX(ctl_fd,sock_fd)+1, &selcopy, 0, 0, &stv)) >= 0 ||
|
(ready = poll(set, 2, timeout * 1000)) >= 0 || errno == EINTR;
|
||||||
errno == EINTR;
|
errno = 0) {
|
||||||
selcopy = devfds, errno = 0, stv = tv) {
|
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (ready == 0) {
|
if (ready == 0) {
|
||||||
@ -453,7 +452,7 @@ main(int argc, char *argv[])
|
|||||||
suspend(ctl_fd);
|
suspend(ctl_fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (FD_ISSET(ctl_fd, &selcopy)) {
|
if (set[0].revents & POLLIN) {
|
||||||
suspends = standbys = resumes = 0;
|
suspends = standbys = resumes = 0;
|
||||||
while (ioctl(ctl_fd, APM_IOC_NEXTEVENT, &apmevent) == 0) {
|
while (ioctl(ctl_fd, APM_IOC_NEXTEVENT, &apmevent) == 0) {
|
||||||
if (debug)
|
if (debug)
|
||||||
@ -515,7 +514,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
if (ready == 0)
|
if (ready == 0)
|
||||||
continue;
|
continue;
|
||||||
if (FD_ISSET(sock_fd, &selcopy)) {
|
if (set[1].revents & POLLIN) {
|
||||||
switch (handle_client(sock_fd, ctl_fd)) {
|
switch (handle_client(sock_fd, ctl_fd)) {
|
||||||
case NORMAL:
|
case NORMAL:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user