- funnel_state = thread_funnel_set(kernel_flock, TRUE);
-
-again:
- if ((tp->t_state&TS_ISOPEN) == 0)
- goto block;
- if (pti->pt_flags & PF_REMOTE) {
- if (tp->t_canq.c_cc)
- goto block;
- while ((uio_resid(uio) > 0 || cc > 0) &&
- tp->t_canq.c_cc < TTYHOG - 1) {
- if (cc == 0) {
- cc = min(uio_resid(uio), BUFSIZ);
- cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc);
- cp = locbuf;
- error = uiomove((caddr_t)cp, cc, uio);
- if (error)
- goto out;
- /* check again for safety */
- if ((tp->t_state & TS_ISOPEN) == 0) {
- /* adjust as usual */
- uio_setresid(uio, (uio_resid(uio) + cc));
- error = EIO;
- goto out;
- }
- }
- if (cc > 0) {
- cc = b_to_q((u_char *)cp, cc, &tp->t_canq);
- /*
- * XXX we don't guarantee that the canq size
- * is >= TTYHOG, so the above b_to_q() may
- * leave some bytes uncopied. However, space
- * is guaranteed for the null terminator if
- * we don't fail here since (TTYHOG - 1) is
- * not a multiple of CBSIZE.
- */
- if (cc > 0)
- break;
- }
- }
- /* adjust for data copied in but not written */
- uio_setresid(uio, (uio_resid(uio) + cc));
- (void) putc(0, &tp->t_canq);
- ttwakeup(tp);
- wakeup(TSA_PTS_READ(tp));
- goto out;
- }
- while (uio_resid(uio) > 0 || cc > 0) {
- if (cc == 0) {
- cc = min(uio_resid(uio), BUFSIZ);
- cp = locbuf;
- error = uiomove((caddr_t)cp, cc, uio);
- if (error)
- goto out;
- /* check again for safety */
- if ((tp->t_state & TS_ISOPEN) == 0) {
- /* adjust for data copied in but not written */
- uio_setresid(uio, (uio_resid(uio) + cc));
- error = EIO;
- goto out;
- }
- }
- while (cc > 0) {
- if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
- (tp->t_canq.c_cc > 0 || !(tp->t_lflag&ICANON))) {
- wakeup(TSA_HUP_OR_INPUT(tp));
- goto block;
- }
- (*linesw[tp->t_line].l_rint)(*cp++, tp);
- wcnt++;
- cc--;
- }
- cc = 0;
- }
-out:
- (void) thread_funnel_set(kernel_flock, funnel_state);
- return (error);
-block:
- /*
- * Come here to wait for slave to open, for space
- * in outq, or space in rawq, or an empty canq.
- */
- if ((tp->t_state & TS_CONNECTED) == 0) {
- /* adjust for data copied in but not written */
- uio_setresid(uio, (uio_resid(uio) + cc));
- error = EIO;
- goto out;
- }
- if (flag & IO_NDELAY) {
- /* adjust for data copied in but not written */
- uio_setresid(uio, (uio_resid(uio) + cc));
- if (wcnt == 0)
- error = EWOULDBLOCK;
- goto out;
- }
- error = tsleep(TSA_PTC_WRITE(tp), TTOPRI | PCATCH, "ptmx_out", 0);
- if (error) {
- /* adjust for data copied in but not written */
- uio_setresid(uio, (uio_resid(uio) + cc));
- goto out;