+
+ttnread(tp)
+ struct tty *tp;
+{
+ int nread = 0;
+
+ if (tp->t_local & LPENDIN)
+ ttypend(tp);
+ nread = tp->t_canq.c_cc;
+ if (tp->t_flags & (RAW|CBREAK))
+ nread += tp->t_rawq.c_cc;
+ return (nread);
+}
+
+ttselect(dev, rw)
+ dev_t dev;
+ int rw;
+{
+ register struct tty *tp = &cdevsw[major(dev)].d_ttys[minor(dev)];
+ int nread;
+ int s = spl5();
+
+ switch (rw) {
+
+ case FREAD:
+ nread = ttnread(tp);
+ if (nread > 0)
+ goto win;
+ if (tp->t_rsel && tp->t_rsel->p_wchan == (caddr_t)&selwait)
+ tp->t_state |= TS_RCOLL;
+ else
+ tp->t_rsel = u.u_procp;
+ break;
+
+ case FWRITE:
+ if (tp->t_outq.c_cc <= TTLOWAT(tp))
+ goto win;
+printf("wsel block\n");
+ if (tp->t_wsel && tp->t_wsel->p_wchan == (caddr_t)&selwait)
+ tp->t_state |= TS_WCOLL;
+ else
+ tp->t_wsel = u.u_procp;
+ break;
+ }
+ splx(s);
+ return (0);
+win:
+ splx(s);
+ return (1);
+}