本文介绍了Winsock中是否有等效于TCP_CORK的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多UNIX TCP实现中,提供了套接字选项 TCP_CORK 呼叫者会绕过 Nagle的算法,并明确指定何时发送物理数据包. Windows(Winsock)是否有等效功能?

In many UNIX TCP implementations, a socket option TCP_CORK is provided which allows the caller to bypass Nagle's algorithm and explicitly specify when to send a physical packet. Is there an equivalent feature in Windows (Winsock)?

(我知道 TCP_NODELAY ,但这不是我所需要的;我仍然希望在发送缓冲区中积累多次写入,然后在准备好发送物理数据包时触发TCP堆栈)

(I'm aware of TCP_NODELAY, but this isn't what I need; I still want multiple writes to be accumulated in the send buffer, and then trigger the TCP stack when I'm ready for it to send a physical packet.)

推荐答案

FWIW我成功使用TCP_NODELAY获得了TCP_CORK样式的行为.我是这样的:

FWIW I successfully use TCP_NODELAY to get TCP_CORK-style behavior. I do it like this:

  1. 取消设置套接字上的TCP_NODELAY标志
  2. 调用send()零次或多次,以将传出数据添加到Nagle队列中
  3. 在套接字上设置TCP_NODELAY标志
  4. 调用send()并将字节数参数设置为零,以强制立即发送Nagle排队的数据

在Windows,MacOS/X和Linux下,对我来说效果很好. (请注意,在Linux下,最后的零字节send()是不必要的)

That works fine for me under Windows, MacOS/X, and Linux. (Note that under Linux the final zero-byte send() isn't necessary)

这篇关于Winsock中是否有等效于TCP_CORK的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:59
查看更多