If the EPOLLET value is set in the eventsfield of theeventparameter passed toepoll_ctl(), the watch onfdis edge-triggered, as opposed to level-triggered.
Consider the following events between a producer and a consumer communicating over a Unix pipe:
The producer writes 1 KB of data onto a pipe.
The consumer performs anepoll_wait()on the pipe, waiting for the pipe to contain data, and thus be readable.
With a level-triggered watch, the call toepoll_wait()in step 2 will return immediately, showing that the pipe is ready to read. With an edge-triggered watch, this call will not return until after step 1 occurs. That is, even if the pipe is readable at the invocation ofepoll_wait(), the call will not return until the data is written onto the pipe.
Level-triggered is the default behavior. It is howpoll()andselect()behave, and it is what most developers expect. Edge-triggered behavior requires a different approach to programming, commonly utilizing nonblocking I/O, and careful checking forEAGAIN.
The terminology comes from electrical engineering. A level-triggered interrupt is issued whenever a line is asserted. An edge-triggered interrupt is caused only during the rising or falling edge of the change in assertion. Level-triggered interrupts are useful when the state of the event (the asserted line) is of interest. Edge-triggered interrupts are useful when the event itself (the line being asserted) is of interest.
Please check back next week for the continuation of this article