forked from premiere/premiere-libtorrent
shave down session_interface by one function, reduce the dependencies between torrent and session
This commit is contained in:
parent
720bfa54cd
commit
a33c81ad33
|
@ -187,6 +187,7 @@ nobase_include_HEADERS = \
|
|||
aux_/session_impl.hpp \
|
||||
aux_/session_settings.hpp \
|
||||
aux_/session_udp_sockets.hpp \
|
||||
aux_/set_socket_buffer.hpp \
|
||||
aux_/proxy_settings.hpp \
|
||||
aux_/session_interface.hpp \
|
||||
aux_/suggest_piece.hpp \
|
||||
|
|
|
@ -781,14 +781,12 @@ namespace aux {
|
|||
peer_class_pool m_classes;
|
||||
|
||||
void init();
|
||||
// void init_dht();
|
||||
|
||||
void submit_disk_jobs();
|
||||
|
||||
void on_trigger_auto_manage();
|
||||
|
||||
void on_lsd_peer(tcp::endpoint const& peer, sha1_hash const& ih) override;
|
||||
void setup_socket_buffers(socket_type& s) override;
|
||||
|
||||
void set_external_address(std::shared_ptr<listen_socket_t> const& sock, address const& ip
|
||||
, ip_source_t const source_type, address const& source);
|
||||
|
|
|
@ -291,7 +291,6 @@ namespace libtorrent { namespace aux {
|
|||
virtual void announce_lsd(sha1_hash const& ih, int port, bool broadcast = false) = 0;
|
||||
virtual libtorrent::utp_socket_manager* utp_socket_manager() = 0;
|
||||
virtual void inc_boost_connections() = 0;
|
||||
virtual void setup_socket_buffers(socket_type& s) = 0;
|
||||
virtual std::vector<block_info>& block_info_storage() = 0;
|
||||
|
||||
#ifdef TORRENT_USE_OPENSSL
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2018, Arvid Norberg, Magnus Jonsson
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TORRENT_SET_SOCKET_BUFFER_HPP
|
||||
#define TORRENT_SET_SOCKET_BUFFER_HPP
|
||||
|
||||
#include "libtorrent/aux_/session_settings.hpp"
|
||||
#include "libtorrent/error_code.hpp"
|
||||
|
||||
namespace libtorrent {
|
||||
namespace aux {
|
||||
|
||||
template <class Socket>
|
||||
void set_socket_buffer_size(Socket& s, session_settings const& sett, error_code& ec)
|
||||
{
|
||||
int const snd_size = sett.get_int(settings_pack::send_socket_buffer_size);
|
||||
if (snd_size)
|
||||
{
|
||||
typename Socket::send_buffer_size prev_option;
|
||||
s.get_option(prev_option, ec);
|
||||
if (!ec && prev_option.value() != snd_size)
|
||||
{
|
||||
typename Socket::send_buffer_size option(snd_size);
|
||||
s.set_option(option, ec);
|
||||
if (ec)
|
||||
{
|
||||
// restore previous value
|
||||
s.set_option(prev_option, ec);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
int const recv_size = sett.get_int(settings_pack::recv_socket_buffer_size);
|
||||
if (recv_size)
|
||||
{
|
||||
typename Socket::receive_buffer_size prev_option;
|
||||
s.get_option(prev_option, ec);
|
||||
if (!ec && prev_option.value() != recv_size)
|
||||
{
|
||||
typename Socket::receive_buffer_size option(recv_size);
|
||||
s.set_option(option, ec);
|
||||
if (ec)
|
||||
{
|
||||
// restore previous value
|
||||
s.set_option(prev_option, ec);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
|
@ -88,6 +88,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/aux_/bind_to_device.hpp"
|
||||
#include "libtorrent/hex.hpp" // to_hex, from_hex
|
||||
#include "libtorrent/aux_/scope_end.hpp"
|
||||
#include "libtorrent/aux_/set_socket_buffer.hpp"
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
|
||||
|
@ -1007,50 +1008,6 @@ namespace aux {
|
|||
return m_port_filter;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
template <class Socket>
|
||||
void set_socket_buffer_size(Socket& s, session_settings const& sett, error_code& ec)
|
||||
{
|
||||
int const snd_size = sett.get_int(settings_pack::send_socket_buffer_size);
|
||||
if (snd_size)
|
||||
{
|
||||
typename Socket::send_buffer_size prev_option;
|
||||
s.get_option(prev_option, ec);
|
||||
if (!ec && prev_option.value() != snd_size)
|
||||
{
|
||||
typename Socket::send_buffer_size option(snd_size);
|
||||
s.set_option(option, ec);
|
||||
if (ec)
|
||||
{
|
||||
// restore previous value
|
||||
s.set_option(prev_option, ec);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
int const recv_size = sett.get_int(settings_pack::recv_socket_buffer_size);
|
||||
if (recv_size)
|
||||
{
|
||||
typename Socket::receive_buffer_size prev_option;
|
||||
s.get_option(prev_option, ec);
|
||||
if (!ec && prev_option.value() != recv_size)
|
||||
{
|
||||
typename Socket::receive_buffer_size option(recv_size);
|
||||
s.set_option(option, ec);
|
||||
if (ec)
|
||||
{
|
||||
// restore previous value
|
||||
s.set_option(prev_option, ec);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
peer_class_t session_impl::create_peer_class(char const* name)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
@ -3031,7 +2988,19 @@ namespace {
|
|||
if (m_alerts.should_post<incoming_connection_alert>())
|
||||
m_alerts.emplace_alert<incoming_connection_alert>(s->type(), endp);
|
||||
|
||||
setup_socket_buffers(*s);
|
||||
{
|
||||
error_code err;
|
||||
set_socket_buffer_size(*s, m_settings, err);
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
if (err && should_log())
|
||||
{
|
||||
error_code ignore;
|
||||
session_log("socket buffer size [ %s %d]: (%d) %s"
|
||||
, s->local_endpoint().address().to_string(ignore).c_str()
|
||||
, s->local_endpoint().port(), err.value(), err.message().c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
peer_connection_args pack;
|
||||
pack.ses = this;
|
||||
|
@ -3064,12 +3033,6 @@ namespace {
|
|||
}
|
||||
}
|
||||
|
||||
void session_impl::setup_socket_buffers(socket_type& s)
|
||||
{
|
||||
error_code ec;
|
||||
set_socket_buffer_size(s, m_settings, ec);
|
||||
}
|
||||
|
||||
void session_impl::close_connection(peer_connection* p) noexcept
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
|
|
@ -98,6 +98,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/disk_io_thread.hpp" // for cache_status
|
||||
#include "libtorrent/aux_/numeric_cast.hpp"
|
||||
#include "libtorrent/aux_/path.hpp"
|
||||
#include "libtorrent/aux_/set_socket_buffer.hpp"
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
#include "libtorrent/aux_/session_impl.hpp" // for tracker_logger
|
||||
|
@ -6577,7 +6578,19 @@ namespace libtorrent {
|
|||
#endif
|
||||
}
|
||||
|
||||
m_ses.setup_socket_buffers(*s);
|
||||
{
|
||||
error_code err;
|
||||
aux::set_socket_buffer_size(*s, settings(), err);
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
if (err && should_log())
|
||||
{
|
||||
error_code ignore;
|
||||
debug_log("socket buffer size [ %s %d]: (%d) %s"
|
||||
, s->local_endpoint().address().to_string(ignore).c_str()
|
||||
, s->local_endpoint().port(), ignore.value(), ignore.message().c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
peer_connection_args pack;
|
||||
pack.ses = &m_ses;
|
||||
|
|
Loading…
Reference in New Issue