From 84dda7b617689ae66d937b7fd63f9208f2a0bea2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 1 May 2009 04:59:15 +0000 Subject: [PATCH] support for adjusting the socket buffer sizes through session_settings --- ChangeLog | 2 ++ docs/manual.rst | 10 ++++++++++ include/libtorrent/aux_/session_impl.hpp | 1 + include/libtorrent/session_settings.hpp | 7 +++++++ src/session_impl.cpp | 19 +++++++++++++++++++ src/torrent.cpp | 2 ++ 6 files changed, 41 insertions(+) diff --git a/ChangeLog b/ChangeLog index abdd486cd..b2c2c0dd2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + * added support for changing socket buffer sizes through + session_settings * added support for merkle hash tree torrents (.merkle.torrent) * added 'seed mode', which assumes that all files are complete and checks hashes lazily, as blocks are requested diff --git a/docs/manual.rst b/docs/manual.rst index 64972f913..60d286216 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3357,6 +3357,9 @@ that will be sent to the tracker. The user-agent is a good way to identify your bool lock_disk_cache; int max_rejects; + + int recv_socket_buffer_size; + int send_socket_buffer_size; }; ``user_agent`` this is the client identification to the tracker. @@ -3702,6 +3705,13 @@ while a peer is choked before the peer is considered abusive and is disconnected. +``recv_socket_buffer_size`` and ``send_socket_buffer_size`` specifies +the buffer sizes set on peer sockets. 0 (which is the default) means +the OS default (i.e. don't change the buffer sizes). The socket buffer +sizes are changed using setsockopt() with SOL_SOCKET/SO_RCVBUF and +SO_SNDBUFFER. + + pe_settings =========== diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index c70db7755..aaf223e24 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -346,6 +346,7 @@ namespace libtorrent void dht_state_callback(boost::condition& c , entry& e, bool& done) const; void on_lsd_peer(tcp::endpoint peer, sha1_hash const& ih); + void setup_socket_buffers(socket_type& s); #ifndef TORRENT_DISABLE_POOL_ALLOCATOR // this pool is used to allocate and recycle send diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index fa8e60a79..072835358 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -161,6 +161,8 @@ namespace libtorrent , lock_disk_cache(true) #endif , max_rejects(50) + , recv_socket_buffer_size(0) + , send_socket_buffer_size(0) {} // this is the user agent that will be sent to the tracker @@ -534,6 +536,11 @@ namespace libtorrent // the number of times to reject requests while being // choked before disconnecting a peer for being malicious int max_rejects; + + // sets the socket send and receive buffer sizes + // 0 means OS default + int recv_socket_buffer_size; + int send_socket_buffer_size; }; #ifndef TORRENT_DISABLE_DHT diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 309427a8a..ee88c7dee 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1006,6 +1006,8 @@ namespace aux { return; } + setup_socket_buffers(*s); + boost::intrusive_ptr c( new bt_peer_connection(*this, s, endp, 0)); #ifdef TORRENT_DEBUG @@ -1019,6 +1021,23 @@ namespace aux { } } + void session_impl::setup_socket_buffers(socket_type& s) + { + error_code ec; + if (m_settings.send_socket_buffer_size) + { + boost::asio::socket_base::send_buffer_size option( + m_settings.send_socket_buffer_size); + s.set_option(option, ec); + } + if (m_settings.recv_socket_buffer_size) + { + boost::asio::socket_base::receive_buffer_size option( + m_settings.recv_socket_buffer_size); + s.set_option(option, ec); + } + } + void session_impl::on_socks_accept(boost::shared_ptr const& s , error_code const& e) { diff --git a/src/torrent.cpp b/src/torrent.cpp index 1f54c38be..74bf8c4e8 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3519,6 +3519,8 @@ namespace libtorrent (void)ret; TORRENT_ASSERT(ret); + m_ses.setup_socket_buffers(*s); + boost::intrusive_ptr c(new bt_peer_connection( m_ses, shared_from_this(), s, a, peerinfo));