英文:
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, &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<IPPROTO_TCP, TCP_QUICKACK>;
s.set_option(quickack(true));
I'd prefer the simple way that makes it clear that you're not promising any portable option.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论