MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / ptsdev_read

Function ptsdev_read

components/lwp/terminal/freebsd/tty_pts.c:84–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82 */
83
84static int ptsdev_read(struct lwp_tty *tp, struct uio *uio,
85 struct ucred *active_cred, int oflags,
86 struct rt_thread *td)
87{
88 struct pts_softc *psc = tty_softc(tp);
89 int error = 0;
90 char pkt;
91
92 if (uio->uio_resid == 0)
93 return (0);
94
95 tty_lock(tp);
96
97 for (;;)
98 {
99 /*
100 * Implement packet mode. When packet mode is turned on,
101 * the first byte contains a bitmask of events that
102 * occurred (start, stop, flush, window size, etc).
103 */
104 if (psc->pts_flags & PTS_PKT && psc->pts_pkt)
105 {
106 pkt = psc->pts_pkt;
107 psc->pts_pkt = 0;
108 tty_unlock(tp);
109
110 error = uiomove(&pkt, 1, uio);
111 return (error);
112 }
113
114 /*
115 * Transmit regular data.
116 *
117 * XXX: We shouldn't use ttydisc_getc_poll()! Even
118 * though in this implementation, there is likely going
119 * to be data, we should just call ttydisc_getc_uio()
120 * and use its return value to sleep.
121 */
122 if (ttydisc_getc_poll(tp))
123 {
124 if (psc->pts_flags & PTS_PKT)
125 {
126 /*
127 * XXX: Small race. Fortunately PTY
128 * consumers aren't multithreaded.
129 */
130
131 tty_unlock(tp);
132 pkt = TIOCPKT_DATA;
133 error = uiomove(&pkt, 1, uio);
134 if (error)
135 return (error);
136 tty_lock(tp);
137 }
138
139 error = ttydisc_getc_uio(tp, uio);
140 break;
141 }

Callers

nothing calls this directly

Calls 3

uiomoveFunction · 0.85
ttydisc_getc_pollFunction · 0.85
ttydisc_getc_uioFunction · 0.85

Tested by

no test coverage detected