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

Function ptsdev_poll

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

Source from the content-addressed store, hash-verified

376}
377
378static int ptsdev_poll(struct lwp_tty *tp, struct rt_pollreq *req,
379 struct ucred *active_cred, struct rt_thread *td)
380{
381 struct pts_softc *psc = tty_softc(tp);
382 int revents = 0;
383 int events = req->_key;
384
385 tty_lock(tp);
386
387 if (psc->pts_flags & PTS_FINISHED)
388 {
389 /* Slave device is not opened. */
390 tty_unlock(tp);
391 return ((events & (POLLIN | POLLRDNORM)) | POLLHUP);
392 }
393
394 if (events & (POLLIN | POLLRDNORM))
395 {
396 /* See if we can getc something. */
397 if (ttydisc_getc_poll(tp) || (psc->pts_flags & PTS_PKT && psc->pts_pkt))
398 revents |= events & (POLLIN | POLLRDNORM);
399 }
400 if (events & (POLLOUT | POLLWRNORM))
401 {
402 /* See if we can rint something. */
403 if (ttydisc_rint_poll(tp))
404 revents |= events & (POLLOUT | POLLWRNORM);
405 }
406
407 /*
408 * No need to check for POLLHUP here. This device cannot be used
409 * as a callout device, which means we always have a carrier,
410 * because the master is.
411 */
412
413 if (revents == 0)
414 {
415 /*
416 * This code might look misleading, but the naming of
417 * poll events on this side is the opposite of the slave
418 * device.
419 */
420 if (events & (POLLIN | POLLRDNORM))
421 rt_poll_add(&psc->pts_outpoll, req);
422 if (events & (POLLOUT | POLLWRNORM))
423 rt_poll_add(&psc->pts_inpoll, req);
424 }
425
426 tty_unlock(tp);
427
428 return (revents);
429}
430
431#if USING_BSD_KQUEUE
432/*

Callers

nothing calls this directly

Calls 3

ttydisc_getc_pollFunction · 0.85
ttydisc_rint_pollFunction · 0.85
rt_poll_addFunction · 0.85

Tested by

no test coverage detected