This is a discussion on UDP packet loss in a multi-threaded program - Linux ; Hello, I’m working on a software that, basically, records incoming UDP packet on the hard drive. It has two threads: one that listens at the UDP socket and one that writes on the hard drive. There are two memory buffers ...
Hello,
I’m working on a software that, basically, records incoming UDP packet on the hard drive. It has two threads: one that listens at the UDP socket and one that writes on the hard drive. There are two memory buffers to store the UDP packets (at a moment only one is filled, the other one is being recorded on the harddrive). The thread that listens on the socket fills the buffer, and when it reaches a certain size, it switches to the other buffer. Then the ‘writer’ thread records the buffer to the hard drive.
But we loose some packets. It’s related to the write() function, because if we comment this function the number of packet received is correct. I’m not sure how to balance priorities between those two threads: do I need to give more priorities to the receiver thread, or to the writer ?
The mutex (used to protect the buffer switching) seems to be ok. Furthermore, if I send bigger UDP packet (currently I’m sending packet of 300, 400 and 500 bytes) it works: I don’t loose any packet if their size is around 1500 bytes.
Any idea on the reason why I would loose packets ?