summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty_pty.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1997-09-14 02:40:46 +0000
committerpeter <peter@FreeBSD.org>1997-09-14 02:40:46 +0000
commitfbe30e0a2cc277a18dacc18fd5a92709eba6225f (patch)
treec5f5d7bad730b55dcdaf0a8c962f1c84cd47cf9e /sys/kern/tty_pty.c
parent28a822ce34dfd8139083885152dca89380a32229 (diff)
downloadFreeBSD-src-fbe30e0a2cc277a18dacc18fd5a92709eba6225f.zip
FreeBSD-src-fbe30e0a2cc277a18dacc18fd5a92709eba6225f.tar.gz
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)
Diffstat (limited to 'sys/kern/tty_pty.c')
-rw-r--r--sys/kern/tty_pty.c88
1 files changed, 42 insertions, 46 deletions
diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c
index cc46c2a..34e1029 100644
--- a/sys/kern/tty_pty.c
+++ b/sys/kern/tty_pty.c
@@ -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) {
-
- 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 */
-
- 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;
-
-
- 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;
+ return (seltrue(dev, events, p) | POLLHUP);
+ /*
+ * Need to block timeouts (ttrstart).
+ */
+ s = spltty();
+
+ 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);
+
+ 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
OpenPOWER on IntegriCloud