| 161 | } |
| 162 | |
| 163 | static int ptsdev_write(struct lwp_tty *tp, struct uio *uio, |
| 164 | struct ucred *active_cred, int oflags, |
| 165 | struct rt_thread *td) |
| 166 | { |
| 167 | struct pts_softc *psc = tty_softc(tp); |
| 168 | char ib[256], *ibstart; |
| 169 | size_t iblen, rintlen; |
| 170 | int error = 0; |
| 171 | |
| 172 | if (uio->uio_resid == 0) |
| 173 | return (0); |
| 174 | |
| 175 | for (;;) |
| 176 | { |
| 177 | ibstart = ib; |
| 178 | iblen = MIN(uio->uio_resid, sizeof ib); |
| 179 | error = uiomove(ib, iblen, uio); |
| 180 | |
| 181 | tty_lock(tp); |
| 182 | if (error != 0) |
| 183 | { |
| 184 | iblen = 0; |
| 185 | goto done; |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * When possible, avoid the slow path. rint_bypass() |
| 190 | * copies all input to the input queue at once. |
| 191 | */ |
| 192 | MPASS(iblen > 0); |
| 193 | do |
| 194 | { |
| 195 | rintlen = ttydisc_rint_simple(tp, ibstart, iblen); |
| 196 | ibstart += rintlen; |
| 197 | iblen -= rintlen; |
| 198 | if (iblen == 0) |
| 199 | { |
| 200 | /* All data written. */ |
| 201 | break; |
| 202 | } |
| 203 | |
| 204 | /* Maybe the device isn't used anyway. */ |
| 205 | if (psc->pts_flags & PTS_FINISHED) |
| 206 | { |
| 207 | error = -EIO; |
| 208 | goto done; |
| 209 | } |
| 210 | |
| 211 | /* Wait for more data. */ |
| 212 | if (oflags & O_NONBLOCK) |
| 213 | { |
| 214 | error = -EWOULDBLOCK; |
| 215 | goto done; |
| 216 | } |
| 217 | |
| 218 | /* Wake up users on the slave side. */ |
| 219 | ttydisc_rint_done(tp); |
| 220 | error = cv_wait_sig(&psc->pts_inwait, tp->t_mtx); |
nothing calls this directly
no test coverage detected