本文介绍了SOCK_SEQPACKET正在缓冲〜42k的数据,如何将其限制为更少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例客户端( http://pastebin.com/hAbpFPia )和服务器()表示客户端可以将大约42k的数据排队.

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.

使用setsockopt(socket,SOL_SOCKET,SO_SNDBUF,...)在客户端大小上设置大小确实会大大限制缓冲的数据.有什么方法可以从服务器端实施/设置此限制?我尝试在调用accept()之前在accept()ed套接字和套接字上设置SO_RCVBUF,但是对我都不起作用.

Using setsockopt(socket, SOL_SOCKET, SO_SNDBUF,...) to set the size on the client size does limit the buffered data significantly. Is there some way I can enforce/set this limit from the server side? I tried setting SO_RCVBUF on the accept()ed socket and the socket before calling accept() but neither works for me.

使用AF_UNIX.

推荐答案

服务器无法在客户端上强制使用SO_SNDBUF大小.

The server cannot enforce a SO_SNDBUF size on the client.

SO_SNDBUF限制发送方操作系统使用的缓冲区.即使基础网络无法立即发送数据,发送应用程序也可以发送多达SO_SNDBUF字节的数据,直到发送被阻塞为止.当网络堆栈能够接受新发送时,操作系统会谨慎发送此数据.

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(如果接收方的操作系统使用的缓冲区).即使应用程序未调用recv来检索数据,网络堆栈也正在接收(并确认发送者)最多SO_RCVBUF字节.对于Unix域套接字,SO_RCVBUF没有任何作用,但是SO_SNDBUF有作用.

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.

如您所见,两个缓冲区加起来.他们正在网络连接的不同端上工作.它们不会互相影响,并且接收方无法在发送方侧强制执行SO_SNDBUF-因为发送方无法在接收方侧强制执行SO_RCVBUF.

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.

这篇关于SOCK_SEQPACKET正在缓冲〜42k的数据,如何将其限制为更少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 10:46