Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ UDP sockets packet queuing

I am using the same UDP socket for sending and receiving data. I am wondering if packet queuing for DGRAM sockets is already present, or do we have to handle it separately.

If the user code has to handle queueing, how is it done? Do we have separate threads to recvfrom for the socket and put the packet in the reciver_queue and to sendto from another sending_queue?

An example code will be absolutely awesome. Thanks for your help.

like image 892
SkypeMeSM Avatar asked Dec 29 '22 06:12

SkypeMeSM


2 Answers

There is a packet queue. However when the packet queue is filled then UDP packets start getting discarded. When they are discarded they are lost forever so make sure you keep reading data!

like image 85
Goz Avatar answered Jan 05 '23 16:01

Goz


As Goz has noted, there is a packet queue. There is more than one, actually, at various places of the whole pipeline that ends in your application. There are usually some buffers on the NIC, then there are some managed by the kernel. The kernel buffers often can be sized for individual sockets using setsockopt().

As Goz has already noted, UDP packets can be lost on their way to you, or they can arive in different order. If you need both realiability and ordering and if you cannot use TCP instead, you will have to implement some kind of protocol that will provide both atop UDP, e.g. sliding window protocol.

like image 27
wilx Avatar answered Jan 05 '23 17:01

wilx