POLLHUP polling

From JookWiki
Revision as of 07:26, 27 October 2022 by Jookia (talk | contribs) (Sketch out article)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This page is a work in progress

POSIX

https://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html

- only lets you wait for read or write to be unblocked or exceptional

https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html

- give fds and in events such as POLLIN or POLLOUT

- get return events such as POLLIN or POLLOUT or POLLERR or POLLHUP

"The array's members are pollfd structures within which fd specifies an open file descriptor and events and revents are bitmasks constructed by OR'ing a combination of the following event flags:"

"POLLHUP - A device has been disconnected, or a pipe or FIFO has been closed by the last process that had it open for writing. ... This flag is only valid in the revents bitmask; it shall be ignored in the events member."

"In each pollfd structure, poll() shall clear the revents member, except that where the application requested a report on a condition by setting one of the bits of events listed above, poll() shall set the corresponding bit in revents if the requested condition is true. In addition, poll() shall set the POLLHUP, POLLERR, and POLLNVAL flag in revents if the condition is true, even if the application did not set the corresponding bit in events."

"If none of the defined events have occurred on any selected file descriptor, poll() shall wait at least timeout milliseconds for an event to occur on any of the selected file descriptors. If the value of timeout is 0, poll() shall return immediately. If the value of timeout is -1, poll() shall block until a requested event occurs or until the call is interrupted."

"The poll() function shall support regular files, terminal and pseudo-terminal devices, FIFOs, pipes, sockets and STREAMS-based files."

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/poll.h.html

"The <poll.h> header shall define the following symbolic constants, zero or more of which may be OR'ed together to form the events or revents members in the pollfd structure:"

https://groups.google.com/g/comp.unix.programmer/c/bNNadBIEpTo/m/G5gs1mqNhbIJ

- test suite and standards require registration or something

Test code

goal: wait for a file descriptor to close

Linux

https://man7.org/linux/man-pages/man2/poll.2.html

"The field fd contains a file descriptor for an open file."

"The field events is an input parameter, a bit mask specifying the events the application is interested in for the file descriptor fd.  This field may be specified as zero, in which case the only events that can be returned in revents are POLLHUP, POLLERR, and POLLNVAL (see below)."

"POLLHUP - Hang up (only returned in revents; ignored in events). Note that when reading from a channel such as a pipe or a stream socket, this event merely indicates that the peer closed its end of the channel."

"If none of the events requested (and no error) has occurred for any of the file descriptors, then poll() blocks until one of the events occurs."

POLLRDHUP ??

Unix

- sysv

- sunos

BSDs

- netbsd

- freebsd

- openbsd

- illumos

- macos

Windows

wsapoll

Emulation

cygwin

minix

my dosbox code :(