diff --git a/docs/manual.html b/docs/manual.html
index ccaf1f8bf..9298158d4 100644
--- a/docs/manual.html
+++ b/docs/manual.html
@@ -2459,6 +2459,7 @@ struct session_settings
bool use_dht_as_fallback;
bool free_torrent_hashes;
bool upnp_ignore_nonrouters;
+ int send_buffer_watermark;
};
user_agent this is the client identification to the tracker.
@@ -2570,6 +2571,11 @@ cannot be passed back to add_torrent()<
should ignore any broadcast response from a device whose address is not the
configured router for this machine. i.e. it's a way to not talk to other
people's routers by mistake.
+send_buffer_waterbark is the upper limit of the send buffer low-watermark.
+if the send buffer has fewer bytes than this, we'll read another 16kB block
+onto it. If set too small, upload rate capacity will suffer. If set too high,
+memory will be wasted. The actual watermark may be lower than this in case
+the upload rate is low, this is the upper limit.
diff --git a/docs/manual.rst b/docs/manual.rst
index d3b60188b..f0f4e8f5d 100644
--- a/docs/manual.rst
+++ b/docs/manual.rst
@@ -2447,6 +2447,7 @@ that will be sent to the tracker. The user-agent is a good way to identify your
bool use_dht_as_fallback;
bool free_torrent_hashes;
bool upnp_ignore_nonrouters;
+ int send_buffer_watermark;
};
``user_agent`` this is the client identification to the tracker.
@@ -2584,6 +2585,12 @@ should ignore any broadcast response from a device whose address is not the
configured router for this machine. i.e. it's a way to not talk to other
people's routers by mistake.
+``send_buffer_waterbark`` is the upper limit of the send buffer low-watermark.
+if the send buffer has fewer bytes than this, we'll read another 16kB block
+onto it. If set too small, upload rate capacity will suffer. If set too high,
+memory will be wasted. The actual watermark may be lower than this in case
+the upload rate is low, this is the upper limit.
+
pe_settings
===========
diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp
index 2817d27d2..1b70f6c98 100644
--- a/include/libtorrent/session_settings.hpp
+++ b/include/libtorrent/session_settings.hpp
@@ -118,6 +118,7 @@ namespace libtorrent
#endif
, free_torrent_hashes(true)
, upnp_ignore_nonrouters(true)
+ , send_buffer_watermark(80 * 1024)
{}
// this is the user agent that will be sent to the tracker
@@ -298,6 +299,14 @@ namespace libtorrent
// any upnp devices that don't have an address that matches
// our currently configured router.
bool upnp_ignore_nonrouters;
+
+ // if the send buffer has fewer bytes than this, we'll
+ // read another 16kB block onto it. If set too small,
+ // upload rate capacity will suffer. If set too high,
+ // memory will be wasted.
+ // The actual watermark may be lower than this in case
+ // the upload rate is low, this is the upper limit.
+ int send_buffer_watermark;
};
#ifndef TORRENT_DISABLE_DHT
diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp
index 88aa390d6..faa13a9a6 100755
--- a/src/peer_connection.cpp
+++ b/src/peer_connection.cpp
@@ -2421,8 +2421,9 @@ namespace libtorrent
// otherwise there will be no end to how large it will be!
int buffer_size_watermark = int(m_statistics.upload_rate()) / 2;
- if (buffer_size_watermark < 1024) buffer_size_watermark = 1024;
- else if (buffer_size_watermark > 80 * 1024) buffer_size_watermark = 80 * 1024;
+ if (buffer_size_watermark < 512) buffer_size_watermark = 512;
+ else if (buffer_size_watermark > m_ses.settings().send_buffer_watermark)
+ buffer_size_watermark = m_ses.settings().send_buffer_watermark;
while (!m_requests.empty()
&& (send_buffer_size() + m_reading_bytes < buffer_size_watermark)