- if (pti->pt_flags & PF_REMOTE) {
- if (tp->t_rawq.c_cc) {
- if (pti->pt_flags & PF_NBIO) {
- u.u_count += ce - cp;
- u.u_error = EWOULDBLOCK;
- return;
- }
- sleep((caddr_t)&tp->t_rawq.c_cf, TTOPRI);
- goto 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->uio_iovcnt > 0 && tp->t_canq.c_cc < TTYHOG - 1) {
+ iov = uio->uio_iov;
+ if (iov->iov_len == 0) {
+ uio->uio_iovcnt--;
+ uio->uio_iov++;
+ continue;
+ }
+ if (cc == 0) {
+ cc = MIN(iov->iov_len, BUFSIZ);
+ cc = MIN(cc, TTYHOG - 1 - tp->t_canq.c_cc);
+ cp = locbuf;
+ error = uiomove(cp, cc, UIO_WRITE, uio);
+ if (error)
+ return (error);
+ /* check again for safety */
+ if ((tp->t_state&TS_ISOPEN) == 0)
+ return (EIO);
+ }
+ if (cc)
+ (void) b_to_q(cp, cc, &tp->t_canq);
+ cc = 0;
+ }
+ (void) putc(0, &tp->t_canq);
+ ttwakeup(tp);
+ wakeup((caddr_t)&tp->t_canq);
+ return (0);
+ }
+ while (uio->uio_iovcnt > 0) {
+ iov = uio->uio_iov;
+ if (cc == 0) {
+ if (iov->iov_len == 0) {
+ uio->uio_iovcnt--;
+ uio->uio_iov++;
+ continue;