summaryrefslogtreecommitdiff
path: root/sys/kern/tty.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-09-23 16:51:15 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-09-23 16:51:15 +0000
commit6bb276a1685d8546283d224a3d249c66cc329264 (patch)
tree5e1c80d6cad38a8a82f5832e1e315103e7029eb9 /sys/kern/tty.c
parent96675671ec2520ade2f83b31563ab4da72bd443d (diff)
Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater poll(2) functionality instead of emulating it via the select backend. Adapted from NetBSD and including some changes from FreeBSD. Tested by many, deraadt@ OK
Diffstat (limited to 'sys/kern/tty.c')
-rw-r--r--sys/kern/tty.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 924b686d74a..1a86d45a0d6 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.60 2003/08/23 19:21:15 deraadt Exp $ */
+/* $OpenBSD: tty.c,v 1.61 2003/09/23 16:51:12 millert Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -56,6 +56,7 @@
#include <sys/resourcevar.h>
#include <sys/sysctl.h>
#include <sys/pool.h>
+#include <sys/poll.h>
#include <sys/namei.h>
@@ -1026,35 +1027,35 @@ ttioctl(tp, cmd, data, flag, p)
}
int
-ttselect(device, rw, p)
+ttpoll(device, events, p)
dev_t device;
- int rw;
+ int events;
struct proc *p;
{
- register struct tty *tp;
- int nread, s;
+ struct tty *tp;
+ int revents, s;
tp = (*cdevsw[major(device)].d_tty)(device);
+ revents = 0;
s = spltty();
- switch (rw) {
- case FREAD:
- nread = ttnread(tp);
- if (nread > 0 || (!ISSET(tp->t_cflag, CLOCAL) &&
- !ISSET(tp->t_state, TS_CARR_ON)))
- goto win;
- selrecord(p, &tp->t_rsel);
- break;
- case FWRITE:
- if (tp->t_outq.c_cc <= tp->t_lowat) {
-win: splx(s);
- return (1);
- }
- selrecord(p, &tp->t_wsel);
- break;
+ if (events & (POLLIN | POLLRDNORM)) {
+ if (ttnread(tp) > 0 || (!ISSET(tp->t_cflag, CLOCAL) &&
+ !ISSET(tp->t_state, TS_CARR_ON)))
+ revents |= events & (POLLIN | POLLRDNORM);
+ }
+ if (events & (POLLOUT | POLLWRNORM)) {
+ if (tp->t_outq.c_cc <= tp->t_lowat)
+ revents |= events & (POLLOUT | POLLWRNORM);
+ }
+ if (revents == 0) {
+ if (events & (POLLIN | POLLRDNORM))
+ selrecord(p, &tp->t_rsel);
+ if (events & (POLLOUT | POLLWRNORM))
+ selrecord(p, &tp->t_wsel);
}
splx(s);
- return (0);
+ return (revents);
}
struct filterops ttyread_filtops =