简体   繁体   中英

Multiple TCP sockets using RT linux scheduling

If I use SCHED_FIFO and set the process priority to 1 how can I efficiently check when one of multiple tcp connections the process is managing has data available for processing?

Ideally I want to multithread if multiple tcp sockets have data ready for processing.

I think it would look something like an infinite loop checking each socket however it seems as if linux scheduler may have a solution.

Not sure how SCHED_FIFO effects your traditional server design. I mean the usage of listening socket and socket returned by accept. The idea is, main thread should blocked on the listening socket and when the new connection is received it should pass the fd returned by accept to new thread. New thread could be created for all new connections or you can have thread pool to limit it and for better control.

Other idea could be to use a thread which calls select on the fd's and main thread could listen and accept the connection, main thread can queue the new fd and send a notification(could be using signal or pipe) to thread which is waiting on select . once data is received it can use the worker thread from the thread pool to assign the task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM