将套接字接收缓冲区设置为指定的字节数是否与可以存储多少大小的消息直接相关?
示例:
如果100
字节消息通过 UDP 连续发送到设置为4,000
字节的套接字缓冲区,我可以期望缓冲区能够保存40
消息吗?
我认为设置缓冲区大小,如下所示:
int size = 4000;
setsockopt(id, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size));
并让缓冲区从传入的数据包中填充,将导致缓冲区包含 40 条消息。
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.