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:
arvidn 2015-07-11 23:01:27 -04:00
parent ed8e4135b2
commit 2739def57f
15 changed files with 48 additions and 39 deletions

View File

@ -276,7 +276,7 @@ namespace libtorrent
int num_fence_jobs[disk_io_job::num_job_ids];
#endif
};
// this is a singleton consisting of the thread and a queue
// of disk io jobs
struct TORRENT_EXTRA_EXPORT disk_io_thread TORRENT_FINAL

View File

@ -41,8 +41,6 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
using boost::asio::ip::tcp;
struct resolver_interface
{
typedef boost::function<void(error_code const&, std::vector<address> const&)>

View File

@ -182,11 +182,11 @@ namespace libtorrent
//
// .. warning::
// The session object does not cleanly terminate with an external
// io_service. The io_service::run() call _must_ have returned before
// it's safe to destruct the session. Which means you *MUST* call
// session::abort() and save the session_proxy first, then destruct the
// session object, then sync withthe io_service, then destruct the
// session_proxy object.
// ``io_service``. The ``io_service::run()`` call _must_ have returned
// before it's safe to destruct the session. Which means you *MUST*
// call session::abort() and save the session_proxy first, then
// destruct the session object, then sync with the io_service, then
// destruct the session_proxy object.
session(settings_pack const& pack
, io_service& ios
, int flags = start_default_features | add_default_plugins)

View File

@ -68,6 +68,7 @@ namespace libtorrent
using boost::asio::ip::udp;
using boost::asio::async_write;
using boost::asio::async_read;
using boost::asio::null_buffers;
#if TORRENT_USE_IPV6
#ifdef IPV6_V6ONLY

View File

@ -182,6 +182,9 @@ namespace libtorrent
{
typedef tcp::socket::endpoint_type endpoint_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) {}
~socket_type();

View File

@ -109,6 +109,9 @@ namespace libtorrent
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>
void get_option(SocketOption const& opt, error_code& ec)
{

View File

@ -330,7 +330,7 @@ public:
}
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)
{

View File

@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
alert::alert() : m_timestamp(aux::time_now()) {}
alert::alert() : m_timestamp(clock_type::now()) {}
alert::~alert() {}
time_point alert::timestamp() const { return m_timestamp; }

View File

@ -5650,7 +5650,7 @@ namespace libtorrent
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("peer_connection::on_receive_data_nb");
#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)));
return 0;
}

View File

@ -1161,11 +1161,11 @@ namespace aux {
int snd_size = sett.get_int(settings_pack::send_socket_buffer_size);
if (snd_size)
{
tcp::socket::send_buffer_size prev_option;
typename Socket::send_buffer_size prev_option;
s.get_option(prev_option, ec);
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);
if (ec)
{
@ -1178,11 +1178,11 @@ namespace aux {
int recv_size = sett.get_int(settings_pack::recv_socket_buffer_size);
if (recv_size)
{
tcp::socket::receive_buffer_size prev_option;
typename Socket::receive_buffer_size prev_option;
s.get_option(prev_option, ec);
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);
if (ec)
{
@ -1942,16 +1942,6 @@ retry:
}
#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);
}
}
}

View File

@ -39,12 +39,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/string_util.hpp" // for allocate_string_copy
#include "libtorrent/broadcast_socket.hpp" // for is_any
#include "libtorrent/settings_pack.hpp"
#include "libtorrent/error.hpp"
#include "libtorrent/aux_/time.hpp" // for aux::time_now()
#include <stdlib.h>
#include <boost/bind.hpp>
#include <boost/array.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/read.hpp>
#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)
{
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));
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)
{
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));
m_v4_write_subscribed = true;
}
@ -488,7 +490,7 @@ void udp_socket::setup_read(udp::socket* s)
udp::endpoint ep;
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));
}
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
// 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())))
{
udp::endpoint ep6 = ep;
@ -740,11 +745,19 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
ec.clear();
#endif
m_ipv6_sock.bind(ep6, ec);
if (ec) return;
udp::socket::non_blocking_io ioc(true);
m_ipv6_sock.io_control(ioc, ec);
if (ec) return;
setup_read(&m_ipv6_sock);
if (ec != error_code(boost::system::errc::address_not_available
, boost::system::generic_category()))
{
if (ec) return;
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
#if TORRENT_USE_ASSERTS

View File

@ -54,7 +54,7 @@ using namespace libtorrent;
struct dht_server
{
boost::asio::io_service m_ios;
libtorrent::io_service m_ios;
boost::detail::atomic_count m_dht_requests;
udp::socket m_socket;
int m_port;
@ -125,7 +125,7 @@ struct dht_server
, boost::bind(&incoming_packet, _1, _2, &bytes_transferred, &ec, &done));
while (!done)
{
m_ios.run_one();
m_ios.poll_one();
m_ios.reset();
}

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/error_code.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/aux_/time.hpp"
#include "libtorrent/io_service.hpp"
#include "peer_server.hpp"
#include "test_utils.hpp"
@ -50,7 +51,7 @@ using namespace libtorrent;
struct peer_server
{
boost::asio::io_service m_ios;
libtorrent::io_service m_ios;
boost::detail::atomic_count m_peer_requests;
tcp::acceptor m_acceptor;
int m_port;
@ -123,7 +124,7 @@ struct peer_server
m_acceptor.async_accept(socket, from, boost::bind(&new_connection, _1, &ec, &done));
while (!done)
{
m_ios.run_one();
m_ios.poll_one();
m_ios.reset();
}

View File

@ -606,7 +606,7 @@ boost::shared_ptr<torrent_info> create_torrent(std::ostream* file, int piece_siz
// excercise the path when encountering invalid urls
char const* invalid_tracker_url = "http:";
char const* invalid_tracker_protocol = "foo://non/existent-name.com/announce";
file_storage fs;
int total_size = piece_size * num_pieces;
fs.add_file("temporary", total_size);

View File

@ -56,7 +56,7 @@ using namespace libtorrent;
struct udp_tracker
{
boost::asio::io_service m_ios;
libtorrent::io_service m_ios;
boost::detail::atomic_count m_udp_announces;
udp::socket m_socket;
int m_port;