如何为Boost ASIO TCP套接字设置TCP_QUICKACK。

huangapple go评论52阅读模式
英文:

How to set TCP_QUICKACK for Boost ASIO TCP socket

问题

我试图为我的Boost TCP服务器/客户端应用设置TCP_QUICKACK。在Boost asio中找不到TCP_QUICKACK。我该如何设置此选项?

英文:

I am trying to set TCP_QUICKACK for my Boost TCP server/client application. I couldn't find the TCP_QUICKACK in Boost asio. How can I set this option?

答案1

得分: 2

这方面没有Asio风格的选项。但你可以始终使用本地句柄:

    // 如常打开tcp::socket s...

    int i = 1;
    ::setsockopt(s.native_handle(), IPPROTO_TCP, TCP_QUICKACK, &i, sizeof(i));

我没有测试过,但以下代码看起来应该可以通过定义你自己的非便携式选项类型来实现:

    using quickack = asio::detail::socket_option::boolean<IPPROTO_TCP, TCP_QUICKACK>;
    s.set_option(quickack(true));

我更喜欢简单的方式,这样清楚地表明你没有承诺任何便携式选项。
英文:

There's no Asio styled option for this. But you can always use the native handle:

// open tcp::socket s as normal...

int i = 1;
::setsockopt(s.native_handle(), IPPROTO_TCP, TCP_QUICKACK, &amp;i, sizeof(i));

I haven't tested it, but it looks like the following should work by defining your own non-portable option type:

using quickack = asio::detail::socket_option::boolean&lt;IPPROTO_TCP, TCP_QUICKACK&gt;;
s.set_option(quickack(true));

I'd prefer the simple way that makes it clear that you're not promising any portable option.

huangapple
  • 本文由 发表于 2023年4月20日 00:52:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76057042.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定