SOCK_SEQPACKET is buffering ~42k of data, how to limit it to less?

后端 未结 1 511
我寻月下人不归
我寻月下人不归 2021-01-23 08:46

An example client(http://pastebin.com/hAbpFPia) and server(http://pastebin.com/9pL27hkK) using SOCK_SEQPACKET, indicate that the client can queue up ~42k of data.

Using

相关标签:
1条回答
  • 2021-01-23 09:18

    The server cannot enforce a SO_SNDBUF size on the client.

    SO_SNDBUF limits the buffer that the sender's OS uses. The sending application can send up to SO_SNDBUF bytes, even if the underlying network cannot send the data right now, until a send would block. The OS takes care to send this data when the network stack is able to accept a new send.

    SO_RCVBUF if the buffer that the receiver's OS uses. The network stack is receiving (and acknowledging to the sender) up to SO_RCVBUF bytes, even if the application does not call recv to retrieve the data. For unix domain sockets SO_RCVBUF does not have any effect, but SO_SNDBUF has.

    As you can see both buffers sum up. And they are working on different ends of the network connection. They do not affect each other and the receiver cannot enforce a SO_SNDBUF on the sender's side - as the sender cannot enforce a SO_RCVBUF on the receiver's side.

    0 讨论(0)
提交回复
热议问题