Search code examples
boosttcpboost-asioasio

How to set TCP_QUICKACK for Boost ASIO TCP socket


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?


Solution

  • 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.