support for adjusting the socket buffer sizes through session_settings

This commit is contained in:
Arvid Norberg 2009-05-01 04:59:15 +00:00
parent 6ca1c191b6
commit 84dda7b617
6 changed files with 41 additions and 0 deletions

View File

@ -1,3 +1,5 @@
* added support for changing socket buffer sizes through
session_settings
* added support for merkle hash tree torrents (.merkle.torrent) * added support for merkle hash tree torrents (.merkle.torrent)
* added 'seed mode', which assumes that all files are complete * added 'seed mode', which assumes that all files are complete
and checks hashes lazily, as blocks are requested and checks hashes lazily, as blocks are requested

View File

@ -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; bool lock_disk_cache;
int max_rejects; int max_rejects;
int recv_socket_buffer_size;
int send_socket_buffer_size;
}; };
``user_agent`` this is the client identification to the tracker. ``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. 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 pe_settings
=========== ===========

View File

@ -346,6 +346,7 @@ namespace libtorrent
void dht_state_callback(boost::condition& c void dht_state_callback(boost::condition& c
, entry& e, bool& done) const; , entry& e, bool& done) const;
void on_lsd_peer(tcp::endpoint peer, sha1_hash const& ih); void on_lsd_peer(tcp::endpoint peer, sha1_hash const& ih);
void setup_socket_buffers(socket_type& s);
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR #ifndef TORRENT_DISABLE_POOL_ALLOCATOR
// this pool is used to allocate and recycle send // this pool is used to allocate and recycle send

View File

@ -161,6 +161,8 @@ namespace libtorrent
, lock_disk_cache(true) , lock_disk_cache(true)
#endif #endif
, max_rejects(50) , 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 // 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 // the number of times to reject requests while being
// choked before disconnecting a peer for being malicious // choked before disconnecting a peer for being malicious
int max_rejects; 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 #ifndef TORRENT_DISABLE_DHT

View File

@ -1006,6 +1006,8 @@ namespace aux {
return; return;
} }
setup_socket_buffers(*s);
boost::intrusive_ptr<peer_connection> c( boost::intrusive_ptr<peer_connection> c(
new bt_peer_connection(*this, s, endp, 0)); new bt_peer_connection(*this, s, endp, 0));
#ifdef TORRENT_DEBUG #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<socket_type> const& s void session_impl::on_socks_accept(boost::shared_ptr<socket_type> const& s
, error_code const& e) , error_code const& e)
{ {

View File

@ -3519,6 +3519,8 @@ namespace libtorrent
(void)ret; (void)ret;
TORRENT_ASSERT(ret); TORRENT_ASSERT(ret);
m_ses.setup_socket_buffers(*s);
boost::intrusive_ptr<peer_connection> c(new bt_peer_connection( boost::intrusive_ptr<peer_connection> c(new bt_peer_connection(
m_ses, shared_from_this(), s, a, peerinfo)); m_ses, shared_from_this(), s, a, peerinfo));