Packet Relay Planning

I am programming a network protocol over UDP using C / C ++ on Linux. The protocol should be reliable, so I'm going to simulate something like TCP retransmission over UDP.

This can be done using pthreads or fork, but I believe this is overkill and consumes a lot of system resources. The best approach is to use a scheduler.

I probably can't use the internal Linux scheduler as I program in user space. Are there standard C / C ++ libraries for this? What about third-party libraries?

Edit: Some people ask why I do this. Why not use TCP instead?

The answer is that I am implementing a tunneling protocol. If someone tunnels TCP through TCP, the efficiency will be significantly reduced. Here is more information. Why TCP over TCP is a bad idea .

+3
source share
3 answers

Here's an example of how to execute asynchronous coroutines with Boost . Boost manages the overhead of creating a thread to run the coroutine in this case, so you don't need to. If you want the kernel to control your interrupts, you can use an alarm clock and setitimer , but they are very limited in what they can do.

, - , , - select().

+1

"", , "select", , Linux. "man 2 select", , .

-, select() -. , . , -.

+5

, . libevent . select, ( ) FreeBSD, Linux MacOS X ( Windows, ), , . . . , pthread , , , , , - .

+1

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


All Articles