- if ((tp->t_state&(TS_CARR_ON|TS_ISOPEN)) == 0)
- return (EIO);
- pti = &pt_ioctl[minor(dev)];
- if (pti->pt_flags & PF_PKT) {
- if (pti->pt_send) {
- error = ureadc(pti->pt_send, uio);
- if (error)
- return (error);
- pti->pt_send = 0;
- return (0);
+ /*
+ * We want to block until the slave
+ * is open, and there's something to read;
+ * but if we lost the slave or we're NBIO,
+ * then return the appropriate error instead.
+ */
+ for (;;) {
+ if (tp->t_state&TS_ISOPEN) {
+ if (pti->pt_flags&PF_PKT && pti->pt_send) {
+ error = ureadc(pti->pt_send, uio);
+ if (error)
+ return (error);
+ pti->pt_send = 0;
+ return (0);
+ }
+ if (pti->pt_flags&PF_UCNTL && pti->pt_ucntl) {
+ error = ureadc(pti->pt_ucntl, uio);
+ if (error)
+ return (error);
+ pti->pt_ucntl = 0;
+ return (0);
+ }
+ if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0)
+ break;