How to wake up a stream after receiving 2 packets

I am using libnetfilter_queue for my project. From the C application queue, a "queue file descriptor" is available. I have 5 queues and 5 threads to process them. What I want to achieve is to wake the thread when there are exactly 2 packets in the queue. I came up with the use of the select function and an int array indicating how many packets were queued in each queue. After selecting exit s> 0 with the code, I check which queue received the packet and the increment value in the array, if it is more than 2, I wake up the stream. Everything will be fine, but choose to indicate that there is data to read in the queue until I call recv, and I cannot do this, because a separate thread must process these packets. Anyone have an idea how to solve this problem? I know that I can set SO_RCVLOWAT, but this does not solve my problem, because I do not knowwhat size will be these two packages.

+3
source share
2 answers

As recommended by Tobu, epoll is the best choice and it is better than the choice. However, most of these polling functions will indicate that there is an event (data available) if someone is not reading. If possible, use the following model: Use epoll / select to ensure that incoming data activates the workflow. Let the workflow decide what to do with the data (one package, two or more) before doing the work.

OR: One Reader thread-N Workflows: will use epoll to wait and read all incoming data and send it to the queue of the corresponding workflows. Once the package packet reaches the threshold, wake up the Worker thread (using a semaphore).

+3

, - , . epoll , EPOLLET, , .

, , epoll_wait .

+1

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


All Articles