minor cleanups. use libtorrent typedefs for asio. failing to bind IPv6 UDP socket is no longer fatal. removed some redundant listen_failed_alerts
This commit is contained in:
parent
ed8e4135b2
commit
2739def57f
|
@ -276,7 +276,7 @@ namespace libtorrent
|
||||||
int num_fence_jobs[disk_io_job::num_job_ids];
|
int num_fence_jobs[disk_io_job::num_job_ids];
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// this is a singleton consisting of the thread and a queue
|
// this is a singleton consisting of the thread and a queue
|
||||||
// of disk io jobs
|
// of disk io jobs
|
||||||
struct TORRENT_EXTRA_EXPORT disk_io_thread TORRENT_FINAL
|
struct TORRENT_EXTRA_EXPORT disk_io_thread TORRENT_FINAL
|
||||||
|
|
|
@ -41,8 +41,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
|
||||||
using boost::asio::ip::tcp;
|
|
||||||
|
|
||||||
struct resolver_interface
|
struct resolver_interface
|
||||||
{
|
{
|
||||||
typedef boost::function<void(error_code const&, std::vector<address> const&)>
|
typedef boost::function<void(error_code const&, std::vector<address> const&)>
|
||||||
|
|
|
@ -182,11 +182,11 @@ namespace libtorrent
|
||||||
//
|
//
|
||||||
// .. warning::
|
// .. warning::
|
||||||
// The session object does not cleanly terminate with an external
|
// The session object does not cleanly terminate with an external
|
||||||
// io_service. The io_service::run() call _must_ have returned before
|
// ``io_service``. The ``io_service::run()`` call _must_ have returned
|
||||||
// it's safe to destruct the session. Which means you *MUST* call
|
// before it's safe to destruct the session. Which means you *MUST*
|
||||||
// session::abort() and save the session_proxy first, then destruct the
|
// call session::abort() and save the session_proxy first, then
|
||||||
// session object, then sync withthe io_service, then destruct the
|
// destruct the session object, then sync with the io_service, then
|
||||||
// session_proxy object.
|
// destruct the session_proxy object.
|
||||||
session(settings_pack const& pack
|
session(settings_pack const& pack
|
||||||
, io_service& ios
|
, io_service& ios
|
||||||
, int flags = start_default_features | add_default_plugins)
|
, int flags = start_default_features | add_default_plugins)
|
||||||
|
|
|
@ -68,6 +68,7 @@ namespace libtorrent
|
||||||
using boost::asio::ip::udp;
|
using boost::asio::ip::udp;
|
||||||
using boost::asio::async_write;
|
using boost::asio::async_write;
|
||||||
using boost::asio::async_read;
|
using boost::asio::async_read;
|
||||||
|
using boost::asio::null_buffers;
|
||||||
|
|
||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
#ifdef IPV6_V6ONLY
|
#ifdef IPV6_V6ONLY
|
||||||
|
|
|
@ -182,6 +182,9 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
typedef tcp::socket::endpoint_type endpoint_type;
|
typedef tcp::socket::endpoint_type endpoint_type;
|
||||||
typedef tcp::socket::protocol_type protocol_type;
|
typedef tcp::socket::protocol_type protocol_type;
|
||||||
|
|
||||||
|
typedef tcp::socket::receive_buffer_size receive_buffer_size;
|
||||||
|
typedef tcp::socket::send_buffer_size send_buffer_size;
|
||||||
|
|
||||||
explicit socket_type(io_service& ios): m_io_service(ios), m_type(0) {}
|
explicit socket_type(io_service& ios): m_io_service(ios), m_type(0) {}
|
||||||
~socket_type();
|
~socket_type();
|
||||||
|
|
|
@ -109,6 +109,9 @@ namespace libtorrent
|
||||||
|
|
||||||
void set_buf_size(int s);
|
void set_buf_size(int s);
|
||||||
|
|
||||||
|
typedef udp::socket::receive_buffer_size receive_buffer_size;
|
||||||
|
typedef udp::socket::send_buffer_size send_buffer_size;
|
||||||
|
|
||||||
template <class SocketOption>
|
template <class SocketOption>
|
||||||
void get_option(SocketOption const& opt, error_code& ec)
|
void get_option(SocketOption const& opt, error_code& ec)
|
||||||
{
|
{
|
||||||
|
|
|
@ -330,7 +330,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Handler>
|
template <class Handler>
|
||||||
void async_read_some(boost::asio::null_buffers const&, Handler const& handler)
|
void async_read_some(null_buffers const&, Handler const& handler)
|
||||||
{
|
{
|
||||||
if (m_impl == 0)
|
if (m_impl == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace libtorrent {
|
namespace libtorrent {
|
||||||
|
|
||||||
alert::alert() : m_timestamp(aux::time_now()) {}
|
alert::alert() : m_timestamp(clock_type::now()) {}
|
||||||
alert::~alert() {}
|
alert::~alert() {}
|
||||||
time_point alert::timestamp() const { return m_timestamp; }
|
time_point alert::timestamp() const { return m_timestamp; }
|
||||||
|
|
||||||
|
|
|
@ -5650,7 +5650,7 @@ namespace libtorrent
|
||||||
#if defined TORRENT_ASIO_DEBUGGING
|
#if defined TORRENT_ASIO_DEBUGGING
|
||||||
add_outstanding_async("peer_connection::on_receive_data_nb");
|
add_outstanding_async("peer_connection::on_receive_data_nb");
|
||||||
#endif
|
#endif
|
||||||
m_socket->async_read_some(boost::asio::null_buffers(), make_read_handler(
|
m_socket->async_read_some(null_buffers(), make_read_handler(
|
||||||
boost::bind(&peer_connection::on_receive_data_nb, self(), _1, _2)));
|
boost::bind(&peer_connection::on_receive_data_nb, self(), _1, _2)));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1161,11 +1161,11 @@ namespace aux {
|
||||||
int snd_size = sett.get_int(settings_pack::send_socket_buffer_size);
|
int snd_size = sett.get_int(settings_pack::send_socket_buffer_size);
|
||||||
if (snd_size)
|
if (snd_size)
|
||||||
{
|
{
|
||||||
tcp::socket::send_buffer_size prev_option;
|
typename Socket::send_buffer_size prev_option;
|
||||||
s.get_option(prev_option, ec);
|
s.get_option(prev_option, ec);
|
||||||
if (!ec && prev_option.value() != snd_size)
|
if (!ec && prev_option.value() != snd_size)
|
||||||
{
|
{
|
||||||
tcp::socket::send_buffer_size option(snd_size);
|
typename Socket::send_buffer_size option(snd_size);
|
||||||
s.set_option(option, ec);
|
s.set_option(option, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
|
@ -1178,11 +1178,11 @@ namespace aux {
|
||||||
int recv_size = sett.get_int(settings_pack::recv_socket_buffer_size);
|
int recv_size = sett.get_int(settings_pack::recv_socket_buffer_size);
|
||||||
if (recv_size)
|
if (recv_size)
|
||||||
{
|
{
|
||||||
tcp::socket::receive_buffer_size prev_option;
|
typename Socket::receive_buffer_size prev_option;
|
||||||
s.get_option(prev_option, ec);
|
s.get_option(prev_option, ec);
|
||||||
if (!ec && prev_option.value() != recv_size)
|
if (!ec && prev_option.value() != recv_size)
|
||||||
{
|
{
|
||||||
tcp::socket::receive_buffer_size option(recv_size);
|
typename Socket::receive_buffer_size option(recv_size);
|
||||||
s.set_option(option, ec);
|
s.set_option(option, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
|
@ -1942,16 +1942,6 @@ retry:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_device_fails == 2)
|
|
||||||
{
|
|
||||||
// only report this if both IPv4 and IPv6 fails for a device
|
|
||||||
if (m_alerts.should_post<listen_failed_alert>())
|
|
||||||
m_alerts.emplace_alert<listen_failed_alert>(device
|
|
||||||
, listen_failed_alert::bind
|
|
||||||
, error_code(boost::system::errc::no_such_device, generic_category())
|
|
||||||
, listen_failed_alert::tcp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,14 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/string_util.hpp" // for allocate_string_copy
|
#include "libtorrent/string_util.hpp" // for allocate_string_copy
|
||||||
#include "libtorrent/broadcast_socket.hpp" // for is_any
|
#include "libtorrent/broadcast_socket.hpp" // for is_any
|
||||||
#include "libtorrent/settings_pack.hpp"
|
#include "libtorrent/settings_pack.hpp"
|
||||||
|
#include "libtorrent/error.hpp"
|
||||||
#include "libtorrent/aux_/time.hpp" // for aux::time_now()
|
#include "libtorrent/aux_/time.hpp" // for aux::time_now()
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/array.hpp>
|
#include <boost/array.hpp>
|
||||||
#include <boost/system/system_error.hpp>
|
#include <boost/system/system_error.hpp>
|
||||||
|
#include <boost/system/error_code.hpp>
|
||||||
#include <boost/asio/read.hpp>
|
#include <boost/asio/read.hpp>
|
||||||
|
|
||||||
#if defined TORRENT_ASIO_DEBUGGING
|
#if defined TORRENT_ASIO_DEBUGGING
|
||||||
|
@ -217,7 +219,7 @@ void udp_socket::send(udp::endpoint const& ep, char const* p, int len
|
||||||
{
|
{
|
||||||
if (!m_v6_write_subscribed)
|
if (!m_v6_write_subscribed)
|
||||||
{
|
{
|
||||||
m_ipv6_sock.async_send(boost::asio::null_buffers()
|
m_ipv6_sock.async_send(null_buffers()
|
||||||
, boost::bind(&udp_socket::on_writable, this, _1, &m_ipv6_sock));
|
, boost::bind(&udp_socket::on_writable, this, _1, &m_ipv6_sock));
|
||||||
m_v6_write_subscribed = true;
|
m_v6_write_subscribed = true;
|
||||||
}
|
}
|
||||||
|
@ -227,7 +229,7 @@ void udp_socket::send(udp::endpoint const& ep, char const* p, int len
|
||||||
{
|
{
|
||||||
if (!m_v4_write_subscribed)
|
if (!m_v4_write_subscribed)
|
||||||
{
|
{
|
||||||
m_ipv4_sock.async_send(boost::asio::null_buffers()
|
m_ipv4_sock.async_send(null_buffers()
|
||||||
, boost::bind(&udp_socket::on_writable, this, _1, &m_ipv4_sock));
|
, boost::bind(&udp_socket::on_writable, this, _1, &m_ipv4_sock));
|
||||||
m_v4_write_subscribed = true;
|
m_v4_write_subscribed = true;
|
||||||
}
|
}
|
||||||
|
@ -488,7 +490,7 @@ void udp_socket::setup_read(udp::socket* s)
|
||||||
udp::endpoint ep;
|
udp::endpoint ep;
|
||||||
TORRENT_TRY
|
TORRENT_TRY
|
||||||
{
|
{
|
||||||
s->async_receive_from(boost::asio::null_buffers()
|
s->async_receive_from(null_buffers()
|
||||||
, ep, boost::bind(&udp_socket::on_read, this, _1, s));
|
, ep, boost::bind(&udp_socket::on_read, this, _1, s));
|
||||||
}
|
}
|
||||||
TORRENT_CATCH(boost::system::system_error& e)
|
TORRENT_CATCH(boost::system::system_error& e)
|
||||||
|
@ -729,6 +731,9 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
|
// TODO: 2 the udp_socket should really just be a single socket, and the
|
||||||
|
// session should support having more than one, just like with TCP sockets
|
||||||
|
// for now, just make bind failures non-fatal
|
||||||
if (supports_ipv6() && (ep.address().is_v6() || is_any(ep.address())))
|
if (supports_ipv6() && (ep.address().is_v6() || is_any(ep.address())))
|
||||||
{
|
{
|
||||||
udp::endpoint ep6 = ep;
|
udp::endpoint ep6 = ep;
|
||||||
|
@ -740,11 +745,19 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
|
||||||
ec.clear();
|
ec.clear();
|
||||||
#endif
|
#endif
|
||||||
m_ipv6_sock.bind(ep6, ec);
|
m_ipv6_sock.bind(ep6, ec);
|
||||||
if (ec) return;
|
if (ec != error_code(boost::system::errc::address_not_available
|
||||||
udp::socket::non_blocking_io ioc(true);
|
, boost::system::generic_category()))
|
||||||
m_ipv6_sock.io_control(ioc, ec);
|
{
|
||||||
if (ec) return;
|
if (ec) return;
|
||||||
setup_read(&m_ipv6_sock);
|
udp::socket::non_blocking_io ioc(true);
|
||||||
|
m_ipv6_sock.io_control(ioc, ec);
|
||||||
|
if (ec) return;
|
||||||
|
setup_read(&m_ipv6_sock);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ec.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
|
|
|
@ -54,7 +54,7 @@ using namespace libtorrent;
|
||||||
struct dht_server
|
struct dht_server
|
||||||
{
|
{
|
||||||
|
|
||||||
boost::asio::io_service m_ios;
|
libtorrent::io_service m_ios;
|
||||||
boost::detail::atomic_count m_dht_requests;
|
boost::detail::atomic_count m_dht_requests;
|
||||||
udp::socket m_socket;
|
udp::socket m_socket;
|
||||||
int m_port;
|
int m_port;
|
||||||
|
@ -125,7 +125,7 @@ struct dht_server
|
||||||
, boost::bind(&incoming_packet, _1, _2, &bytes_transferred, &ec, &done));
|
, boost::bind(&incoming_packet, _1, _2, &bytes_transferred, &ec, &done));
|
||||||
while (!done)
|
while (!done)
|
||||||
{
|
{
|
||||||
m_ios.run_one();
|
m_ios.poll_one();
|
||||||
m_ios.reset();
|
m_ios.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/error_code.hpp"
|
#include "libtorrent/error_code.hpp"
|
||||||
#include "libtorrent/socket.hpp"
|
#include "libtorrent/socket.hpp"
|
||||||
#include "libtorrent/aux_/time.hpp"
|
#include "libtorrent/aux_/time.hpp"
|
||||||
|
#include "libtorrent/io_service.hpp"
|
||||||
#include "peer_server.hpp"
|
#include "peer_server.hpp"
|
||||||
#include "test_utils.hpp"
|
#include "test_utils.hpp"
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ using namespace libtorrent;
|
||||||
struct peer_server
|
struct peer_server
|
||||||
{
|
{
|
||||||
|
|
||||||
boost::asio::io_service m_ios;
|
libtorrent::io_service m_ios;
|
||||||
boost::detail::atomic_count m_peer_requests;
|
boost::detail::atomic_count m_peer_requests;
|
||||||
tcp::acceptor m_acceptor;
|
tcp::acceptor m_acceptor;
|
||||||
int m_port;
|
int m_port;
|
||||||
|
@ -123,7 +124,7 @@ struct peer_server
|
||||||
m_acceptor.async_accept(socket, from, boost::bind(&new_connection, _1, &ec, &done));
|
m_acceptor.async_accept(socket, from, boost::bind(&new_connection, _1, &ec, &done));
|
||||||
while (!done)
|
while (!done)
|
||||||
{
|
{
|
||||||
m_ios.run_one();
|
m_ios.poll_one();
|
||||||
m_ios.reset();
|
m_ios.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -606,7 +606,7 @@ boost::shared_ptr<torrent_info> create_torrent(std::ostream* file, int piece_siz
|
||||||
// excercise the path when encountering invalid urls
|
// excercise the path when encountering invalid urls
|
||||||
char const* invalid_tracker_url = "http:";
|
char const* invalid_tracker_url = "http:";
|
||||||
char const* invalid_tracker_protocol = "foo://non/existent-name.com/announce";
|
char const* invalid_tracker_protocol = "foo://non/existent-name.com/announce";
|
||||||
|
|
||||||
file_storage fs;
|
file_storage fs;
|
||||||
int total_size = piece_size * num_pieces;
|
int total_size = piece_size * num_pieces;
|
||||||
fs.add_file("temporary", total_size);
|
fs.add_file("temporary", total_size);
|
||||||
|
|
|
@ -56,7 +56,7 @@ using namespace libtorrent;
|
||||||
struct udp_tracker
|
struct udp_tracker
|
||||||
{
|
{
|
||||||
|
|
||||||
boost::asio::io_service m_ios;
|
libtorrent::io_service m_ios;
|
||||||
boost::detail::atomic_count m_udp_announces;
|
boost::detail::atomic_count m_udp_announces;
|
||||||
udp::socket m_socket;
|
udp::socket m_socket;
|
||||||
int m_port;
|
int m_port;
|
||||||
|
|
Loading…
Reference in New Issue