Accept () is interrupted by a signal and epoll_wait ()

If I am epoll_wait () on a listening socket, and when epoll_wait () returns an indication that it has activity (in this case, the connection is waiting to be accepted () ed), then if the call to accept () ends with errno = EINTR, will Does epoll_wait () indicate that the next time it returns, the same connection is awaiting in the listener?

ie, I need to do something line by line:

while(1){ epoll_wait(epfd, &events, maxevents, timeout); if (events.data.fd == listener){ connsock = accept(listener, &addr, &addrlen); while (connsock != -1){ if (errno == EINTR){ accept(listener, &addr, &addrlen); } } } } 

to make sure the connection is accepted, or it will work, and still make sure that the connection for which accept () was interrupted by a signal is accepted:

 while(1){ epoll_wait(epfd, &events, maxevents, timeout); if (events.data.fd == listener){ connsock = accept(listener, &addr, &addrlen); } } 

where in this case, if accept () is interrupted by a signal, it just picks up the same connection the next time through the loop after returning epoll_wait.

Obviously, in both of these examples I make some assumptions (that, for example, only one event in one socket is returned when the epoll_wait call is given) and excludes error checking (except for EINTR on accept (), since all of this is here) to simplify things

+4
source share
1 answer

This is the difference between the trigger and the level trigger. Use the trigger level trigger, by default, and you do not need to worry about it.

The tradeoff with the level trigger is that you cannot have one thread processing the detected event, while the other thread returns to the epoll_wait call - it will just detect the same event again. But in most cases, you still do not need to do this, and the compromise between its inability to lose the event is worth it.

+2
source

Source: https://habr.com/ru/post/1388783/


All Articles