Winsock中是否有等效于TCP_CORK的文件? [英] Is there an equivalent to TCP_CORK in Winsock?

查看:152
本文介绍了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_CORK (自Linux 2.2起)

TCP_CORK (since Linux 2.2)

如果已设置,请不要发送局部帧.再次清除该选项时,将发送所有排队的部分帧.这对于在调用sendfile(2)之前添加标头或进行吞吐量优化很有用.按照当前的实现,TCP_CORK对输出进行软木塞的时间上限为200毫秒.如果达到此上限,则将自动传输排队的数据.仅从Linux 2.5.71开始,此选项才能与TCP_NODELAY结合使用.此选项不应在旨在可移植的代码中使用.

If set, don't send out partial frames. All queued partial frames are sent when the option is cleared again. This is useful for prepending headers before calling sendfile(2), or for throughput optimization. As currently implemented, there is a 200 millisecond ceiling on the time for which output is corked by TCP_CORK. If this ceiling is reached, then queued data is automatically transmitted. This option can be combined with TCP_NODELAY only since Linux 2.5.71. This option should not be used in code intended to be portable.

(我知道

(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的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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