什么是SO_SNDBUF和SO_RECVBUF [英] What are SO_SNDBUF and SO_RECVBUF

查看:452
本文介绍了什么是SO_SNDBUF和SO_RECVBUF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能解释一下SO_SNDBUFSO_RECVBUF选项到底是什么吗?

Can you explain me what exactly are SO_SNDBUF and SO_RECVBUF options?

好的,由于某种原因,操作系统会缓冲传出/传入的数据,但我想澄清一下这个主题.

OK, for some reason the OS buffers the outgoing/incomming data but I'd like to clarify this subject.

(通常)他们的作用是什么?

What is their role (generally)?

它们是按套接字缓存的吗?

Are they per-socket buffers?

传输层的缓冲区(例如TCP缓冲区)与这些缓冲区之间是否存在连接?

Is there a connection between Transport layer's buffers (the TCP buffer, for example) and these buffers?

使用流套接字(TCP)和使用无连接套接字(UDP)时,它们的行为/角色是否不同?

Do they have a different behaviour/role when using stream sockets (TCP) and when using connectionless sockets (UDP)?

好的文章也很棒.

我搜索了它,但没有找到任何有用的信息.

I googled it but didnt find any useful information.

推荐答案

"SO_"前缀用于套接字选项",所以是的,这些是针对每个套接字缓冲区的每个套接字设置.通常有系统范围的默认值和最大值.

The "SO_" prefix is for "socket option", so yes, these are per-socket settings for the per-socket buffers. There are usually system-wide defaults and maximum values.

SO_RCVBUF更易于理解:它是内核分配的缓冲区的大小,用于在数据到达网络之间以及拥有该程序的程序读取数据之间的时间里,存放进入给定套接字的数据.插座.使用TCP,如果数据到达而您没有读取它,则缓冲区将填满,并且将通知发送方放慢速度(使用TCP窗口调整机制).对于UDP,一旦缓冲区已满,新的数据包将被丢弃.

SO_RCVBUF is simpler to understand: it is the size of the buffer the kernel allocates to hold the data arriving into the given socket during the time between it arrives over the network and when it is read by the program that owns this socket. With TCP, if data arrives and you aren't reading it, the buffer will fill up, and the sender will be told to slow down (using TCP window adjustment mechanism). For UDP, once the buffer is full, new packets will just be discarded.

SO_SNDBUF仅对TCP(在UDP中,无论您发送的任何内容都直接发送到网络)都很重要.对于TCP,如果远程端未读取数据,则可以填充缓冲区(因此,远程缓冲区已满,然后TCP将这一事实传达给内核,并且内核停止发送数据,而是将其累积在本地缓冲区中,直到它被发送为止).填上).或者,如果出现网络问题,并且内核没有收到对其发送的数据的确认,它可能会填满.然后它将减慢在网络上发送数据的速度,直到最终传出缓冲区填满为止.如果是这样,应用程序将来对该套接字的write()调用将被阻止(如果设置了O_NONBLOCK选项,则返回EAGAIN.)

SO_SNDBUF, I think, only matters for TCP (in UDP, whatever you send goes directly out to the network). For TCP, you could fill the buffer either if the remote side isn't reading (so that remote buffer becomes full, then TCP communicates this fact to your kernel, and your kernel stops sending data, instead accumulating it in the local buffer until it fills up). Or it could fill up if there is a network problem, and the kernel isn't getting acknowledgements for the data it sends. It will then slow down sending data on the network until, eventually, the outgoing buffer fills up. If so, future write() calls to this socket by the application will block (or return EAGAIN if you've set the O_NONBLOCK option).

Unix网络编程 a>书.

这篇关于什么是SO_SNDBUF和SO_RECVBUF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆