Thoroughly learn to use epoll (two): ET and LT trigger

Editor: wind over the summer ChinaUnix blog

Analysis of the implementation of ET and LT, then analyze their trigger much easier. We know that by implementing analysis epoll_wait wakes up the next LT mode in two ways (in the red and blue lines), and ET mode can only be one way (in the red). So the case of ET mode can wake up the next LT model must also be awakened. We first discuss special circumstances (ET mode), before we discuss the general situation (LT model).

2.1 AND

According to the analysis in the previous section of the two join rdlist way, it can draw wake up the next ET mode (returns to ready) conditions for:

l For a read operation:

(1) When the state becomes unreadable by the read buffer time, i.e., from the empty to not empty.

(2) When new data arrives, i.e., the contents to be read in the buffer becomes more time.

Also add this:

(3) when the data buffer read (i.e., buffer is not empty), and the user event corresponding epoll_mod IN FD (specifically see below section).

In the case of (1) (2) respectively in FIG. 1 (a), FIG. 1 (b).

l For a write operation:

(1) When the write buffer becomes available from non-written, that is, when dissatisfied by the full state to state.

(2) When the old data is sent down, i.e., in the buffer to be written when the content becomes too small.

Also add this:

(3) When there is a writable buffer space (ie, buffer dissatisfaction) and the corresponding user fd be epoll_mod OUT event (see next section specific content).

In the case of (1) (2) respectively in FIG. 2 (a), FIG. 2 (b).

   

                                    (a)                                                                                                       (b)

Figure 1 ET read both cases triggered

Figure 2 LT write two cases triggered

 

2.2 LT

LT mode under process wakes up (descriptors ready) condition is much simpler, which contains all the conditions ET mode, that is, the Sixth read the above listed conditions are to be awakened for the LT model. In addition, there is a more common situation LT can be awakened, and ET is not ignored, which is why we need to pay attention to the situation.

For read operations l

When the data buffer, and the data is read out after a portion of the buffer is not empty, i.e., the content of buffer to reduce the time, the mode returns LT ready for reading. As shown below. 

l For a write operation

When the buffer dissatisfaction, discontent then wrote a throw of time, that is, since the write operation is faster than the transmission speed resulting in an increase in the latter part of the contents of the data buffer when, LT returns to the Ready mode. As shown below.

Note: poll and select are the LT model.

 

Guess you like

Origin www.cnblogs.com/abelchao/p/11703769.html