FreeBSD/sys/kern/tty_pts.c
/*
 * Controller-side file operations.
 */
Controller-side file operations.
Controller - side file operations .
static int
ptsdev_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
    int flags, struct thread *td)
{
	struct tty *tp = fp->f_data;
	struct pts_softc *psc = tty_softc(tp);
	int error = 0;
	char pkt;
	if (uio->uio_resid == 0)
		return (0);
	tty_lock(tp);
	for (;;) {
		if (psc->pts_flags & PTS_PKT && psc->pts_pkt) {
			pkt = psc->pts_pkt;
			psc->pts_pkt = 0;
			tty_unlock(tp);
			error = ureadc(pkt, uio);
			return (error);
		}
		if (ttydisc_getc_poll(tp)) {
			if (psc->pts_flags & PTS_PKT) {
				tty_unlock(tp);
				error = ureadc(TIOCPKT_DATA, uio);
				if (error)
					return (error);
				tty_lock(tp);
			}
			error = ttydisc_getc_uio(tp, uio);
			break;
		}
		if (psc->pts_flags & PTS_FINISHED)
			break;
		if (fp->f_flag & O_NONBLOCK) {
			error = EWOULDBLOCK;
			break;
		}
		error = cv_wait_sig(&psc->pts_outwait, tp->t_mtx);
		if (error != 0)
			break;
	}
	tty_unlock(tp);
	return (error);
}
static int ptsdev_read ( struct file * fp , struct uio * uio , struct ucred * active_cred , int flags , struct thread * td ) { struct tty * tp = fp -> f_data ; struct pts_softc * psc = tty_softc ( tp ) ; int error = 0 ; char pkt ; if ( uio -> uio_resid == 0 ) return ( 0 ) ; tty_lock ( tp ) ; for ( ; ; ) { if ( psc -> pts_flags & PTS_PKT && psc -> pts_pkt ) { pkt = psc -> pts_pkt ; psc -> pts_pkt = 0 ; tty_unlock ( tp ) ; error = ureadc ( pkt , uio ) ; return ( error ) ; } if ( ttydisc_getc_poll ( tp ) ) { if ( psc -> pts_flags & PTS_PKT ) { tty_unlock ( tp ) ; error = ureadc ( TIOCPKT_DATA , uio ) ; if ( error ) return ( error ) ; tty_lock ( tp ) ; } error = ttydisc_getc_uio ( tp , uio ) ; break ; } if ( psc -> pts_flags & PTS_FINISHED ) break ; if ( fp -> f_flag & O_NONBLOCK ) { error = EWOULDBLOCK ; break ; } error = cv_wait_sig ( & psc -> pts_outwait , tp -> t_mtx ) ; if ( error != 0 ) break ; } tty_unlock ( tp ) ; return ( error ) ; }
Controller-side file operations.
Controller - side file operations .
/*
		 * Implement packet mode. When packet mode is turned on,
		 * the first byte contains a bitmask of events that
		 * occurred (start, stop, flush, window size, etc).
		 */ /*
		 * Transmit regular data.
		 *
		 * XXX: We shouldn't use ttydisc_getc_poll()! Even
		 * though in this implementation, there is likely going
		 * to be data, we should just call ttydisc_getc_uio()
		 * and use its return value to sleep.
		 */ /*
				 * XXX: Small race. Fortunately PTY
				 * consumers aren't multithreaded.
				 */ /* Maybe the device isn't used anyway. */ /* Wait for more data. */