I have a question regarding recv (C, Android).
Is recv guaranteed to return a complete UDP datagram when it returns?
In my case I am using recv to read RTP packets from a socket. The expected length of each RTP packet is 172 (160 bytes for payload and 12 for the header). However, I'm not sure whether I have a guarantee that I'll get the complete 172 bytes when recv returns with data.
Can anybody confirm/comment?
Per POSIX, recv returns the entire UDP packet, unless and error occurs or the buffer is too small for the entire packet. You can detect this by setting the MSG_TRUNC flag, which causes recv to return the frame's actual data length, which you can compare to the buffer size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With