Question

I have a UDP socket in blocking mode, I have bursts of packets and some are getting lost.

  1. How can I find out current used size in receive buffer in winsock?
  2. How can I understand whether system is discarding packets?
Was it helpful?

Solution

WSAIoctl passed FIONREAD is documented this way:

If the socket passed in the s parameter is message oriented (for example, type SOCK_DGRAM), FIONREAD returns the reports the total number of bytes available to read, not the size of the first datagram (message) queued on the socket.

I think this answers your first question. As for the second, I see no way to programmatically figure that out. You should use sequence numbers in your application to detect gaps, and then look at the receive buffer size and guess that if it's close to full, the losses are due to running out of buffer space.

OTHER TIPS

The receive buffer size for any socket is given by calling getsockopt() with the SO_RCVBUF option

I don't see how you can distinguish at the receiver between a packet lost in the network and a packet discarded at the local host. All you can tell is that it didn't arrive, and you need a higher-level protocol than UDP to tell you so, a sequence-numbered protocol with ACKs or NACKs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top