diff --git a/ChangeLog b/ChangeLog index faf65d8e4..f51aeab74 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * support TCP_NOTSENT_LOWAT on Linux * fix correct interface binding of local service discovery multicast * fix issue with knowing which interfaces to announce to trackers and DHT * undeprecate settings_pack::dht_upload_rate_limit diff --git a/docs/hunspell/libtorrent.dic b/docs/hunspell/libtorrent.dic index 06403eb9d..f4c316f02 100644 --- a/docs/hunspell/libtorrent.dic +++ b/docs/hunspell/libtorrent.dic @@ -557,3 +557,5 @@ fe80 vcpkg leecher 6881l +NOTSENT +LOWAT diff --git a/include/libtorrent/aux_/set_socket_buffer.hpp b/include/libtorrent/aux_/set_socket_buffer.hpp index e5cc71a07..06ac03514 100644 --- a/include/libtorrent/aux_/set_socket_buffer.hpp +++ b/include/libtorrent/aux_/set_socket_buffer.hpp @@ -42,6 +42,14 @@ namespace aux { template void set_socket_buffer_size(Socket& s, session_settings const& sett, error_code& ec) { +#ifdef TCP_NOTSENT_LOWAT + int const not_sent_low_watermark = sett.get_int(settings_pack::send_not_sent_low_watermark); + if (not_sent_low_watermark) + { + error_code ignore; + s.set_option(tcp_notsent_lowat(not_sent_low_watermark), ignore); + } +#endif int const snd_size = sett.get_int(settings_pack::send_socket_buffer_size); if (snd_size) { diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index e36d87cba..81fb5f04e 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -1729,6 +1729,11 @@ namespace aux { // as zero. resolver_cache_timeout, + // specify the not-sent low watermark for socket send buffers. This + // corresponds to the, Linux-specific, ``TCP_NOTSENT_LOWAT`` TCP socket + // option. + send_not_sent_low_watermark, + max_int_setting_internal }; diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index ffe17b23d..8254a61ab 100644 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -246,6 +246,22 @@ namespace libtorrent { int m_value; }; #endif // TORRENT_USE_NETLINK + +#ifdef TCP_NOTSENT_LOWAT + struct tcp_notsent_lowat + { + explicit tcp_notsent_lowat(int val) : m_value(val) {} + template + int level(Protocol const&) const { return IPPROTO_TCP; } + template + int name(Protocol const&) const { return TCP_NOTSENT_LOWAT; } + template + int const* data(Protocol const&) const { return &m_value; } + template + std::size_t size(Protocol const&) const { return sizeof(m_value); } + int m_value; + }; +#endif } #endif // TORRENT_SOCKET_HPP_INCLUDED diff --git a/src/session.cpp b/src/session.cpp index e3fb1bc11..eb08d5ce0 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -236,8 +236,7 @@ namespace { set.set_int(settings_pack::max_rejects, 10); - set.set_int(settings_pack::recv_socket_buffer_size, 1024 * 1024); - set.set_int(settings_pack::send_socket_buffer_size, 1024 * 1024); + set.set_int(settings_pack::send_not_sent_low_watermark, 524288); // don't let connections linger for too long set.set_int(settings_pack::request_timeout, 10); diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index ee1f5932d..6dfcec422 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -348,6 +348,7 @@ constexpr int CLOSE_FILE_INTERVAL = 0; SET(utp_cwnd_reduce_timer, 100, nullptr), SET(max_web_seed_connections, 3, nullptr), SET(resolver_cache_timeout, 1200, &session_impl::update_resolver_cache_timeout), + SET(send_not_sent_low_watermark, 16384, nullptr), }}); #undef SET