How does the SO_RCVBUF size correlate to incoming packet size?

2.6k views Asked by At

Does setting the socket receive buffer to a specified number of bytes, directly correlate to how many sized messages can be stored?

Example:
If a 100 byte message is being continuously sent over UDP to a socket buffer set at 4,000 bytes, can I expect the buffer to be able to hold 40 messages?

I thought that setting the buffer size, like so:

int size = 4000;
setsockopt(id, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size));  

and letting the buffer fill from incoming packets, would result in a buffer containing 40 messages.

After turning off the UDP sender, and processing the buffer, that is not what I have observed.
Despite my messages being 100 bytes, it seems as though a 4,000 byte buffer could only hold about 4 messages.


How could 100 byte messages be taking up 1,000 bytes in the buffer?
Does this make sense? What is causing this, and how can I calculate a buffer size in accordance to how many messages can be held?


edit: duplicated question does not solve my problem.
The user there was calling setsockopt incorrectly.
I'm trying to find documentation that describes the relationship between a socket recieve buffer, and the number of sized messages that can actually be held.

0

There are 0 answers