MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ptsdev_poll

Function ptsdev_poll

freebsd/kern/tty_pts.c:392–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390}
391
392static int
393ptsdev_poll(struct file *fp, int events, struct ucred *active_cred,
394 struct thread *td)
395{
396 struct tty *tp = fp->f_data;
397 struct pts_softc *psc = tty_softc(tp);
398 int revents = 0;
399
400 tty_lock(tp);
401
402 if (psc->pts_flags & PTS_FINISHED) {
403 /* Slave device is not opened. */
404 tty_unlock(tp);
405 return ((events & (POLLIN|POLLRDNORM)) | POLLHUP);
406 }
407
408 if (events & (POLLIN|POLLRDNORM)) {
409 /* See if we can getc something. */
410 if (ttydisc_getc_poll(tp) ||
411 (psc->pts_flags & PTS_PKT && psc->pts_pkt))
412 revents |= events & (POLLIN|POLLRDNORM);
413 }
414 if (events & (POLLOUT|POLLWRNORM)) {
415 /* See if we can rint something. */
416 if (ttydisc_rint_poll(tp))
417 revents |= events & (POLLOUT|POLLWRNORM);
418 }
419
420 /*
421 * No need to check for POLLHUP here. This device cannot be used
422 * as a callout device, which means we always have a carrier,
423 * because the master is.
424 */
425
426 if (revents == 0) {
427 /*
428 * This code might look misleading, but the naming of
429 * poll events on this side is the opposite of the slave
430 * device.
431 */
432 if (events & (POLLIN|POLLRDNORM))
433 selrecord(td, &psc->pts_outpoll);
434 if (events & (POLLOUT|POLLWRNORM))
435 selrecord(td, &psc->pts_inpoll);
436 }
437
438 tty_unlock(tp);
439
440 return (revents);
441}
442
443/*
444 * kqueue support.

Callers

nothing calls this directly

Calls 3

ttydisc_getc_pollFunction · 0.85
ttydisc_rint_pollFunction · 0.85
selrecordFunction · 0.85

Tested by

no test coverage detected