forked from premiere/premiere-libtorrent
if setting socket send or receive buffer size fails, reset it to the previous value
This commit is contained in:
parent
1dc491e7e1
commit
515cd24a8c
|
@ -133,6 +133,20 @@ public:
|
|||
return m_sock.set_option(opt, ec);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
template <class GettableSocketOption>
|
||||
void set_option(GettableSocketOption& opt)
|
||||
{
|
||||
m_sock.get_option(opt);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class GettableSocketOption>
|
||||
error_code get_option(GettableSocketOption& opt, error_code& ec)
|
||||
{
|
||||
return m_sock.get_option(opt, ec);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
void bind(endpoint_type const& endpoint)
|
||||
{
|
||||
|
|
|
@ -253,6 +253,17 @@ namespace libtorrent
|
|||
error_code set_option(SettableSocketOption const& opt, error_code& ec)
|
||||
{ TORRENT_SOCKTYPE_FORWARD_RET(set_option(opt, ec), ec) }
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
template <class GettableSocketOption>
|
||||
void get_option(GettableSocketOption& opt)
|
||||
{ TORRENT_SOCKTYPE_FORWARD(get_option(opt)) }
|
||||
#endif
|
||||
|
||||
template <class GettableSocketOption>
|
||||
error_code get_option(GettableSocketOption& opt, error_code& ec)
|
||||
{ TORRENT_SOCKTYPE_FORWARD_RET(get_option(opt, ec), ec) }
|
||||
|
||||
|
||||
template <class S>
|
||||
void instantiate(io_service& ios, void* userdata = 0)
|
||||
{
|
||||
|
|
|
@ -106,6 +106,15 @@ namespace libtorrent
|
|||
|
||||
void set_buf_size(int s);
|
||||
|
||||
template <class SocketOption>
|
||||
void get_option(SocketOption const& opt, error_code& ec)
|
||||
{
|
||||
m_ipv4_sock.get_option(opt, ec);
|
||||
#if TORRENT_USE_IPV6
|
||||
m_ipv6_sock.get_option(opt, ec);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class SocketOption>
|
||||
void set_option(SocketOption const& opt, error_code& ec)
|
||||
{
|
||||
|
|
|
@ -208,6 +208,15 @@ public:
|
|||
template <class SettableSocketOption>
|
||||
error_code set_option(SettableSocketOption const& opt, error_code& ec) { return ec; }
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
template <class GettableSocketOption>
|
||||
void get_option(GettableSocketOption& opt) {}
|
||||
#endif
|
||||
|
||||
template <class GettableSocketOption>
|
||||
error_code get_option(GettableSocketOption& opt, error_code& ec) { return ec; }
|
||||
|
||||
|
||||
void close();
|
||||
void close(error_code const& /*ec*/) { close(); }
|
||||
bool is_open() const { return m_open; }
|
||||
|
|
|
@ -1944,6 +1944,45 @@ namespace aux {
|
|||
m_disk_thread.add_job(j);
|
||||
}
|
||||
|
||||
template <class Socket>
|
||||
void static set_socket_buffer_size(Socket& s, session_settings const& sett, error_code& ec)
|
||||
{
|
||||
if (sett.send_socket_buffer_size)
|
||||
{
|
||||
stream_socket::send_buffer_size prev_option;
|
||||
s.get_option(prev_option, ec);
|
||||
if (!ec)
|
||||
{
|
||||
stream_socket::send_buffer_size option(
|
||||
sett.send_socket_buffer_size);
|
||||
s.set_option(option, ec);
|
||||
if (ec)
|
||||
{
|
||||
// restore previous value
|
||||
s.set_option(prev_option, ec);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sett.recv_socket_buffer_size)
|
||||
{
|
||||
stream_socket::receive_buffer_size prev_option;
|
||||
s.get_option(prev_option, ec);
|
||||
if (!ec)
|
||||
{
|
||||
stream_socket::receive_buffer_size option(
|
||||
sett.recv_socket_buffer_size);
|
||||
s.set_option(option, ec);
|
||||
if (ec)
|
||||
{
|
||||
// restore previous value
|
||||
s.set_option(prev_option, ec);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void session_impl::set_settings(session_settings const& s)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
@ -2082,19 +2121,14 @@ namespace aux {
|
|||
#endif
|
||||
}
|
||||
|
||||
if (m_settings.send_socket_buffer_size != s.send_socket_buffer_size)
|
||||
{
|
||||
error_code ec;
|
||||
stream_socket::send_buffer_size option(
|
||||
m_settings.send_socket_buffer_size);
|
||||
m_udp_socket.set_option(option, ec);
|
||||
}
|
||||
if (m_settings.recv_socket_buffer_size != s.recv_socket_buffer_size)
|
||||
{
|
||||
error_code ec;
|
||||
stream_socket::receive_buffer_size option(
|
||||
m_settings.recv_socket_buffer_size);
|
||||
m_udp_socket.set_option(option, ec);
|
||||
set_socket_buffer_size(m_udp_socket, m_settings, ec);
|
||||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<udp_error_alert>())
|
||||
m_alerts.post_alert(udp_error_alert(udp::endpoint(), ec));
|
||||
}
|
||||
}
|
||||
|
||||
bool reopen_listen_port = false;
|
||||
|
@ -2479,17 +2513,12 @@ retry:
|
|||
(*m_logger) << ">>> SET_TOS[ udp_socket tos: " << m_settings.peer_tos << " e: " << ec.message() << " ]\n";
|
||||
#endif
|
||||
ec.clear();
|
||||
if (m_settings.send_socket_buffer_size)
|
||||
|
||||
set_socket_buffer_size(m_udp_socket, m_settings, ec);
|
||||
if (ec)
|
||||
{
|
||||
stream_socket::send_buffer_size option(
|
||||
m_settings.send_socket_buffer_size);
|
||||
m_udp_socket.set_option(option, ec);
|
||||
}
|
||||
if (m_settings.recv_socket_buffer_size)
|
||||
{
|
||||
stream_socket::receive_buffer_size option(
|
||||
m_settings.recv_socket_buffer_size);
|
||||
m_udp_socket.set_option(option, ec);
|
||||
if (m_alerts.should_post<udp_error_alert>())
|
||||
m_alerts.post_alert(udp_error_alert(udp::endpoint(), ec));
|
||||
}
|
||||
|
||||
// initiate accepting on the listen sockets
|
||||
|
@ -2971,18 +3000,7 @@ retry:
|
|||
void session_impl::setup_socket_buffers(socket_type& s)
|
||||
{
|
||||
error_code ec;
|
||||
if (m_settings.send_socket_buffer_size)
|
||||
{
|
||||
stream_socket::send_buffer_size option(
|
||||
m_settings.send_socket_buffer_size);
|
||||
s.set_option(option, ec);
|
||||
}
|
||||
if (m_settings.recv_socket_buffer_size)
|
||||
{
|
||||
stream_socket::receive_buffer_size option(
|
||||
m_settings.recv_socket_buffer_size);
|
||||
s.set_option(option, ec);
|
||||
}
|
||||
set_socket_buffer_size(s, m_settings, ec);
|
||||
}
|
||||
|
||||
void session_impl::on_socks_accept(boost::shared_ptr<socket_type> const& s
|
||||
|
|
|
@ -89,7 +89,7 @@ int print_failures()
|
|||
return tests_failure;
|
||||
}
|
||||
|
||||
std::auto_ptr<alert> wait_for_alert(session& ses, int type)
|
||||
std::auto_ptr<alert> wait_for_alert(session& ses, int type, char const* name)
|
||||
{
|
||||
std::auto_ptr<alert> ret;
|
||||
while (!ret.get())
|
||||
|
@ -100,6 +100,7 @@ std::auto_ptr<alert> wait_for_alert(session& ses, int type)
|
|||
for (std::deque<alert*>::iterator i = alerts.begin()
|
||||
, end(alerts.end()); i != end; ++i)
|
||||
{
|
||||
fprintf(stderr, "%s: %s: [%s] %s\n", time_now_string(), name, (*i)->what(), (*i)->message().c_str());
|
||||
if (!ret.get() && (*i)->type() == type)
|
||||
{
|
||||
ret = std::auto_ptr<alert>(*i);
|
||||
|
@ -595,6 +596,14 @@ setup_transfer(session* ses1, session* ses2, session* ses3
|
|||
|
||||
if (connect_peers)
|
||||
{
|
||||
std::auto_ptr<alert> a;
|
||||
do
|
||||
{
|
||||
a = wait_for_alert(*ses2, state_changed_alert::alert_type, "ses2");
|
||||
} while (static_cast<state_changed_alert*>(a.get())->state != torrent_status::downloading);
|
||||
|
||||
wait_for_alert(*ses1, torrent_finished_alert::alert_type, "ses1");
|
||||
|
||||
error_code ec;
|
||||
if (use_ssl_ports)
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ int EXPORT load_file(std::string const& filename, std::vector<char>& v, libtorre
|
|||
|
||||
void EXPORT report_failure(char const* err, char const* file, int line);
|
||||
|
||||
std::auto_ptr<libtorrent::alert> EXPORT wait_for_alert(libtorrent::session& ses, int type);
|
||||
std::auto_ptr<libtorrent::alert> EXPORT wait_for_alert(libtorrent::session& ses, int type, char const* name = "");
|
||||
|
||||
void EXPORT print_ses_rate(float time
|
||||
, libtorrent::torrent_status const* st1
|
||||
|
|
|
@ -97,11 +97,15 @@ void test_rate()
|
|||
file.close();
|
||||
|
||||
wait_for_listen(ses1, "ses1");
|
||||
wait_for_listen(ses2, "ses1");
|
||||
wait_for_listen(ses2, "ses2");
|
||||
|
||||
peer_disconnects = 0;
|
||||
|
||||
session_settings sett = high_performance_seed();
|
||||
sett.enable_outgoing_utp = true;
|
||||
sett.enable_incoming_utp = true;
|
||||
sett.enable_outgoing_tcp = false;
|
||||
sett.enable_incoming_tcp = false;
|
||||
ses1.set_settings(sett);
|
||||
ses2.set_settings(sett);
|
||||
|
||||
|
|
Loading…
Reference in New Issue