Extend to use poll backend. If memory serves correctly, most of this was
adapted from NetBSD.. However, there are some differences in the tty system that are big enough to cause their code to not fit comfortably. Obtained from: NetBSD (I think)
This commit is contained in:
parent
6b8e64f55f
commit
6183953301
@ -36,7 +36,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)tty.c 8.8 (Berkeley) 1/21/94
|
||||
* $Id: tty.c,v 1.94 1997/03/24 12:02:59 bde Exp $
|
||||
* $Id: tty.c,v 1.95 1997/09/02 20:05:54 bde Exp $
|
||||
*/
|
||||
|
||||
/*-
|
||||
@ -83,6 +83,7 @@
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/dkstat.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/signalvar.h>
|
||||
@ -1031,35 +1032,34 @@ ttioctl(tp, cmd, data, flag)
|
||||
}
|
||||
|
||||
int
|
||||
ttyselect(tp, rw, p)
|
||||
ttypoll(tp, events, p)
|
||||
struct tty *tp;
|
||||
int rw;
|
||||
int events;
|
||||
struct proc *p;
|
||||
{
|
||||
int s;
|
||||
int revents = 0;
|
||||
|
||||
if (tp == NULL)
|
||||
return (ENXIO);
|
||||
if (tp == NULL) /* XXX used to return ENXIO, but that means true! */
|
||||
return ((events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM))
|
||||
| POLLHUP);
|
||||
|
||||
s = spltty();
|
||||
switch (rw) {
|
||||
case FREAD:
|
||||
if (events & (POLLIN | POLLRDNORM))
|
||||
if (ttnread(tp) > 0 || ISSET(tp->t_state, TS_ZOMBIE))
|
||||
goto win;
|
||||
selrecord(p, &tp->t_rsel);
|
||||
break;
|
||||
case FWRITE:
|
||||
revents |= events & (POLLIN | POLLRDNORM);
|
||||
else
|
||||
selrecord(p, &tp->t_rsel);
|
||||
|
||||
if (events & (POLLOUT | POLLWRNORM))
|
||||
if ((tp->t_outq.c_cc <= tp->t_lowat &&
|
||||
ISSET(tp->t_state, TS_CONNECTED))
|
||||
|| ISSET(tp->t_state, TS_ZOMBIE)) {
|
||||
win: splx(s);
|
||||
return (1);
|
||||
}
|
||||
selrecord(p, &tp->t_wsel);
|
||||
break;
|
||||
}
|
||||
|| ISSET(tp->t_state, TS_ZOMBIE))
|
||||
revents |= events & (POLLOUT | POLLWRNORM);
|
||||
else
|
||||
selrecord(p, &tp->t_wsel);
|
||||
splx(s);
|
||||
return (0);
|
||||
return (revents);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1067,12 +1067,12 @@ win: splx(s);
|
||||
* cdevsw. It relies on a proper xxxdevtotty routine.
|
||||
*/
|
||||
int
|
||||
ttselect(dev, rw, p)
|
||||
ttpoll(dev, events, p)
|
||||
dev_t dev;
|
||||
int rw;
|
||||
int events;
|
||||
struct proc *p;
|
||||
{
|
||||
return ttyselect((*cdevsw[major(dev)]->d_devtotty)(dev), rw, p);
|
||||
return ttypoll((*cdevsw[major(dev)]->d_devtotty)(dev), events, p);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -31,7 +31,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
|
||||
* $Id: tty_pty.c,v 1.44 1997/07/30 10:05:18 jmg Exp $
|
||||
* $Id: tty_pty.c,v 1.45 1997/09/02 20:05:55 bde Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -49,6 +49,7 @@
|
||||
#include <sys/tty.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/signalvar.h>
|
||||
@ -74,19 +75,19 @@ static d_open_t ptcopen;
|
||||
static d_close_t ptcclose;
|
||||
static d_read_t ptcread;
|
||||
static d_write_t ptcwrite;
|
||||
static d_select_t ptcselect;
|
||||
static d_poll_t ptcpoll;
|
||||
|
||||
#define CDEV_MAJOR_S 5
|
||||
#define CDEV_MAJOR_C 6
|
||||
static struct cdevsw pts_cdevsw =
|
||||
{ ptsopen, ptsclose, ptsread, ptswrite, /*5*/
|
||||
ptyioctl, ptsstop, nullreset, ptydevtotty,/* ttyp */
|
||||
ttselect, nommap, NULL, "pts", NULL, -1 };
|
||||
ttpoll, nommap, NULL, "pts", NULL, -1 };
|
||||
|
||||
static struct cdevsw ptc_cdevsw =
|
||||
{ ptcopen, ptcclose, ptcread, ptcwrite, /*6*/
|
||||
ptyioctl, nullstop, nullreset, ptydevtotty,/* ptyp */
|
||||
ptcselect, nommap, NULL, "ptc", NULL, -1 };
|
||||
ptcpoll, nommap, NULL, "ptc", NULL, -1 };
|
||||
|
||||
|
||||
#if NPTY == 1
|
||||
@ -459,58 +460,53 @@ ptsstop(tp, flush)
|
||||
}
|
||||
|
||||
static int
|
||||
ptcselect(dev, rw, p)
|
||||
ptcpoll(dev, events, p)
|
||||
dev_t dev;
|
||||
int rw;
|
||||
int events;
|
||||
struct proc *p;
|
||||
{
|
||||
register struct tty *tp = &pt_tty[minor(dev)];
|
||||
struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
|
||||
int revents = 0;
|
||||
int s;
|
||||
|
||||
if ((tp->t_state & TS_CONNECTED) == 0)
|
||||
return (1);
|
||||
switch (rw) {
|
||||
return (seltrue(dev, events, p) | POLLHUP);
|
||||
|
||||
case FREAD:
|
||||
/*
|
||||
* Need to block timeouts (ttrstart).
|
||||
*/
|
||||
s = spltty();
|
||||
if ((tp->t_state&TS_ISOPEN) &&
|
||||
tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) {
|
||||
splx(s);
|
||||
return (1);
|
||||
}
|
||||
splx(s);
|
||||
/* FALLTHROUGH */
|
||||
/*
|
||||
* Need to block timeouts (ttrstart).
|
||||
*/
|
||||
s = spltty();
|
||||
|
||||
case 0: /* exceptional */
|
||||
if ((tp->t_state&TS_ISOPEN) &&
|
||||
((pti->pt_flags&PF_PKT && pti->pt_send) ||
|
||||
(pti->pt_flags&PF_UCNTL && pti->pt_ucntl)))
|
||||
return (1);
|
||||
selrecord(p, &pti->pt_selr);
|
||||
break;
|
||||
if (events & (POLLIN | POLLRDNORM))
|
||||
if ((tp->t_state & TS_ISOPEN) &&
|
||||
((tp->t_outq.c_cc && (tp->t_state & TS_TTSTOP) == 0) ||
|
||||
((pti->pt_flags & PF_PKT) && pti->pt_send) ||
|
||||
((pti->pt_flags & PF_UCNTL) && pti->pt_ucntl)))
|
||||
revents |= events & (POLLIN | POLLRDNORM);
|
||||
|
||||
if (events & (POLLOUT | POLLWRNORM))
|
||||
if (tp->t_state & TS_ISOPEN &&
|
||||
((pti->pt_flags & PF_REMOTE) ?
|
||||
(tp->t_canq.c_cc == 0) :
|
||||
((tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG - 2) ||
|
||||
(tp->t_canq.c_cc == 0 && (tp->t_iflag & ICANON)))))
|
||||
revents |= events & (POLLOUT | POLLWRNORM);
|
||||
|
||||
case FWRITE:
|
||||
if (tp->t_state&TS_ISOPEN) {
|
||||
if (pti->pt_flags & PF_REMOTE) {
|
||||
if (tp->t_canq.c_cc == 0)
|
||||
return (1);
|
||||
} else {
|
||||
if (tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG-2)
|
||||
return (1);
|
||||
if (tp->t_canq.c_cc == 0 && (tp->t_iflag&ICANON))
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
selrecord(p, &pti->pt_selw);
|
||||
break;
|
||||
if (events & POLLHUP)
|
||||
if ((tp->t_state & TS_CARR_ON) == 0)
|
||||
revents |= POLLHUP;
|
||||
|
||||
if (revents == 0) {
|
||||
if (events & (POLLIN | POLLRDNORM))
|
||||
selrecord(p, &pti->pt_selr);
|
||||
|
||||
if (events & (POLLOUT | POLLWRNORM))
|
||||
selrecord(p, &pti->pt_selw);
|
||||
}
|
||||
return (0);
|
||||
splx(s);
|
||||
|
||||
return (revents);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -31,13 +31,14 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)tty_tty.c 8.2 (Berkeley) 9/23/93
|
||||
* $Id: tty_tty.c,v 1.16 1997/03/24 11:24:38 bde Exp $
|
||||
* $Id: tty_tty.c,v 1.17 1997/09/02 20:05:56 bde Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
* Indirect driver for controlling tty.
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/tty.h>
|
||||
@ -52,14 +53,14 @@ static d_open_t cttyopen;
|
||||
static d_read_t cttyread;
|
||||
static d_write_t cttywrite;
|
||||
static d_ioctl_t cttyioctl;
|
||||
static d_select_t cttyselect;
|
||||
static d_poll_t cttypoll;
|
||||
|
||||
#define CDEV_MAJOR 1
|
||||
/* Don't make static, fdesc_vnops uses this. */
|
||||
struct cdevsw ctty_cdevsw =
|
||||
{ cttyopen, nullclose, cttyread, cttywrite, /*1*/
|
||||
cttyioctl, nullstop, nullreset, nodevtotty,/* tty */
|
||||
cttyselect, nommap, NULL, "ctty", NULL, -1 };
|
||||
cttypoll, nommap, NULL, "ctty", NULL, -1 };
|
||||
|
||||
|
||||
#define cttyvp(p) ((p)->p_flag & P_CONTROLT ? (p)->p_session->s_ttyvp : NULL)
|
||||
@ -160,16 +161,17 @@ cttyioctl(dev, cmd, addr, flag, p)
|
||||
|
||||
/*ARGSUSED*/
|
||||
static int
|
||||
cttyselect(dev, flag, p)
|
||||
cttypoll(dev, events, p)
|
||||
dev_t dev;
|
||||
int flag;
|
||||
int events;
|
||||
struct proc *p;
|
||||
{
|
||||
struct vnode *ttyvp = cttyvp(p);
|
||||
|
||||
if (ttyvp == NULL)
|
||||
return (1); /* try operation to get EOF/failure */
|
||||
return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p));
|
||||
/* try operation to get EOF/failure */
|
||||
return (seltrue(dev, events, p));
|
||||
return (VOP_POLL(ttyvp, events, p->p_ucred, p));
|
||||
}
|
||||
|
||||
static ctty_devsw_installed = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user