SO_RCVBUF怎么会比TCP接收窗口小呢? (Windows XP)
我有一个在 Windows XP 上使用 TCP 的应用程序。当我使用 SO_RCVBUF 选项调用 getsockopt 时,它报告 8192 字节。然而,Wireshark 显示该应用程序宣传的接收缓冲区为 64K。这怎么可能?要有64K的接收窗口,难道不需要64K的缓冲区吗?有两个不同的缓冲区吗?
I have an application using TCP on Windows XP. When I call getsockopt with the SO_RCVBUF option, it reports 8192 bytes. However, Wireshark shows the app advertising a receive buffer of 64K. How is this possible? To have a 64K receive window, doesn't it need a 64K buffer? Are there two different buffers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在研究这个问题,我认为 SO_RCVBUF 和 TCP 窗口不一定是同一件事。
如果您查看 http://msdn.microsoft.com/en-us/magazine /cc302334.aspx 部分“Windows NT 和 Windows 2000 套接字体系结构” 您会看到 Windows 内核套接字驱动程序 Afd.sys 位于传输协议之上。它有自己的套接字
SND
/RCV
缓冲区,这些缓冲区是您在套接字选项SO_SNDBUF
、中设置的>SO_RCVBUF
或通过 Afd 注册表项。然后 TCP 传输协议有自己的 TCP 窗口缓冲区,这是每个人都熟悉的,并且可以在注册表 Tcpip 参数中设置,或者自动确定考虑到 SO_RCVBUF ,我认为是混乱从何而来。 http://msdn.microsoft.com/en-us/library/ms819736.aspx
因此,我相信数据会根据需要从传输层读取到 afd.sys 套接字缓冲区
SO_RCVBUF
中,等待应用程序读出。您可能希望 SO_RCVBUF 至少与您希望一次读取的数据一样大。但是我不知道
SO_RCVBUF
和 TCP 窗口将如何相互作用。 TCP 是否会等待 ACK 数据,直至将其读入SO_RCVBUF
中?我不清楚。I'm looking into this, and I don't think
SO_RCVBUF
and the TCP Window are necessarily the same thing.If you look at http://msdn.microsoft.com/en-us/magazine/cc302334.aspx section "The Windows NT and Windows 2000 Sockets Architecture" you see that the Windows Kernel Socket driver Afd.sys sits on top of the Transport protocols. It has its own socket
SND
/RCV
buffers which are what you set in the socket optionsSO_SNDBUF
,SO_RCVBUF
or via Afd registry keys.Then the TCP transport protocol has its own TCP Window Buffer which is the one everyone is familiar with and is set either in the registry Tcpip parameters or is determined automatically bearing in mind among other things SO_RCVBUF which I think is where the confusion comes from. http://msdn.microsoft.com/en-us/library/ms819736.aspx
So I believe data is read from the transport layer into the afd.sys socket buffer
SO_RCVBUF
as needed where it waits to be read out by the application. You would want theSO_RCVBUF
to be at least as large as the data you hope to read at once.However I don't know how the
SO_RCVBUF
and TCP Window will interplay. Will TCP wait to ACK data until it is read intoSO_RCVBUF
? That is unclear to me.您自己设置窗口大小吗?确保在
connect(2)
或accept(2)
之前执行此操作。但 Windows 在这方面可能比较特殊,请检查 msdn。Are you setting the window size yourself? Make sure you do that before
connect(2)
oraccept(2)
. But again windows might be special in this regard, check the msdn.