improve error message for listen_failed_alert
This commit is contained in:
parent
c9fae9c0ed
commit
a75a0581e3
|
@ -979,9 +979,11 @@ namespace libtorrent
|
|||
{
|
||||
listen_failed_alert(
|
||||
tcp::endpoint const& ep
|
||||
, int op
|
||||
, error_code const& ec)
|
||||
: endpoint(ep)
|
||||
, error(ec)
|
||||
, operation(op)
|
||||
{}
|
||||
|
||||
TORRENT_DEFINE_ALERT(listen_failed_alert);
|
||||
|
@ -992,6 +994,11 @@ namespace libtorrent
|
|||
|
||||
tcp::endpoint endpoint;
|
||||
error_code error;
|
||||
enum op_t
|
||||
{
|
||||
parse_addr, open, bind, listen, get_peer_name, accept
|
||||
};
|
||||
int operation;
|
||||
};
|
||||
|
||||
struct TORRENT_EXPORT listen_succeeded_alert: alert
|
||||
|
|
|
@ -90,7 +90,6 @@ namespace libtorrent
|
|||
|
||||
void send(udp::endpoint const& ep, char const* p, int len, error_code& ec, int flags = 0);
|
||||
void bind(udp::endpoint const& ep, error_code& ec);
|
||||
void bind(int port);
|
||||
void close();
|
||||
int local_port() const { return m_bind_port; }
|
||||
|
||||
|
|
|
@ -283,9 +283,20 @@ namespace libtorrent {
|
|||
|
||||
std::string listen_failed_alert::message() const
|
||||
{
|
||||
char ret[200];
|
||||
snprintf(ret, sizeof(ret), "listening on %s failed: %s"
|
||||
, print_endpoint(endpoint).c_str(), convert_from_native(error.message()).c_str());
|
||||
char const* op_str[] =
|
||||
{
|
||||
"parse_addr",
|
||||
"open",
|
||||
"bind",
|
||||
"listen",
|
||||
"get_peer_name",
|
||||
"accept"
|
||||
};
|
||||
char ret[250];
|
||||
snprintf(ret, sizeof(ret), "listening on %s failed: [%s] %s"
|
||||
, print_endpoint(endpoint).c_str()
|
||||
, op_str[operation]
|
||||
, convert_from_native(error.message()).c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -2130,10 +2130,14 @@ namespace aux {
|
|||
void session_impl::setup_listener(listen_socket_t* s, tcp::endpoint ep
|
||||
, int& retries, bool v6_only, int flags, error_code& ec)
|
||||
{
|
||||
int last_op = 0;
|
||||
s->sock.reset(new socket_acceptor(m_io_service));
|
||||
s->sock->open(ep.protocol(), ec);
|
||||
last_op = listen_failed_alert::open;
|
||||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log("failed to open socket: %s: %s"
|
||||
, print_endpoint(ep).c_str(), ec.message().c_str());
|
||||
|
@ -2173,6 +2177,7 @@ namespace aux {
|
|||
--retries;
|
||||
ep.port(ep.port() + 1);
|
||||
s->sock->bind(ep, ec);
|
||||
last_op = listen_failed_alert::bind;
|
||||
}
|
||||
if (ec && !(flags & session::listen_no_system_port))
|
||||
{
|
||||
|
@ -2181,12 +2186,13 @@ namespace aux {
|
|||
ep.port(0);
|
||||
ec = error_code();
|
||||
s->sock->bind(ep, ec);
|
||||
last_op = listen_failed_alert::bind;
|
||||
}
|
||||
if (ec)
|
||||
{
|
||||
// not even that worked, give up
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(ep, ec));
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log("cannot bind to interface \"%s\": %s"
|
||||
, print_endpoint(ep).c_str(), ec.message().c_str());
|
||||
|
@ -2194,11 +2200,16 @@ namespace aux {
|
|||
return;
|
||||
}
|
||||
s->external_port = s->sock->local_endpoint(ec).port();
|
||||
if (!ec) s->sock->listen(m_settings.listen_queue_size, ec);
|
||||
last_op = listen_failed_alert::get_peer_name;
|
||||
if (!ec)
|
||||
{
|
||||
s->sock->listen(m_settings.listen_queue_size, ec);
|
||||
last_op = listen_failed_alert::listen;
|
||||
}
|
||||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(ep, ec));
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log("cannot listen on interface \"%s\": %s"
|
||||
, print_endpoint(ep).c_str(), ec.message().c_str());
|
||||
|
@ -2209,7 +2220,21 @@ namespace aux {
|
|||
// if we asked the system to listen on port 0, which
|
||||
// socket did it end up choosing?
|
||||
if (ep.port() == 0)
|
||||
{
|
||||
ep.port(s->sock->local_endpoint(ec).port());
|
||||
last_op = listen_failed_alert::get_peer_name;
|
||||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
char msg[200];
|
||||
snprintf(msg, 200, "failed to get peer name \"%s\": %s"
|
||||
, print_endpoint(ep).c_str(), ec.message().c_str());
|
||||
(*m_logger) << time_now_string() << msg << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (m_alerts.should_post<listen_succeeded_alert>())
|
||||
m_alerts.post_alert(listen_succeeded_alert(ep));
|
||||
|
@ -2377,7 +2402,8 @@ retry:
|
|||
goto retry;
|
||||
}
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(m_listen_interface, ec));
|
||||
m_alerts.post_alert(listen_failed_alert(m_listen_interface
|
||||
, listen_failed_alert::bind, ec));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2499,7 +2525,7 @@ retry:
|
|||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(tcp::endpoint(
|
||||
address_v4::any(), m_listen_interface.port()), e));
|
||||
address_v4::any(), m_listen_interface.port()), listen_failed_alert::accept, e));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log("cannot bind to port %d: %s"
|
||||
, m_listen_interface.port(), e.message().c_str());
|
||||
|
@ -2635,7 +2661,7 @@ retry:
|
|||
async_accept(listener, ssl);
|
||||
}
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(ep, e));
|
||||
m_alerts.post_alert(listen_failed_alert(ep, listen_failed_alert::accept, e));
|
||||
return;
|
||||
}
|
||||
async_accept(listener, ssl);
|
||||
|
@ -2889,7 +2915,7 @@ retry:
|
|||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(tcp::endpoint(
|
||||
address_v4::any(), m_listen_interface.port()), e));
|
||||
address_v4::any(), m_listen_interface.port()), listen_failed_alert::accept, e));
|
||||
return;
|
||||
}
|
||||
open_new_incoming_socks_connection();
|
||||
|
@ -5332,6 +5358,9 @@ retry:
|
|||
new_interface = tcp::endpoint(address::from_string(net_interface, ec), port_range.first);
|
||||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(new_interface, listen_failed_alert::parse_addr, ec));
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log("listen_on: %s failed: %s"
|
||||
, net_interface, ec.message().c_str());
|
||||
|
|
|
@ -1137,7 +1137,7 @@ namespace libtorrent
|
|||
#if BOOST_VERSION == 103500
|
||||
error_code(boost::system::posix_error::not_enough_memory, get_posix_category())
|
||||
#elif BOOST_VERSION > 103500
|
||||
error_code(boost::system::errc::not_enough_memory, get_posix_category())
|
||||
error_code(boost::system::errc::not_enough_memory, boost::system::generic_category())
|
||||
#else
|
||||
asio::error::no_memory
|
||||
#endif
|
||||
|
|
|
@ -132,11 +132,14 @@ void udp_socket::send_hostname(char const* hostname, int port
|
|||
{
|
||||
CHECK_MAGIC;
|
||||
|
||||
TORRENT_ASSERT(is_open());
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
// if the sockets are closed, the udp_socket is closing too
|
||||
if (!is_open()) return;
|
||||
if (!is_open())
|
||||
{
|
||||
ec = error_code(boost::system::errc::bad_file_descriptor, boost::system::generic_category());
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_tunnel_packets)
|
||||
{
|
||||
|
@ -166,11 +169,14 @@ void udp_socket::send(udp::endpoint const& ep, char const* p, int len
|
|||
{
|
||||
CHECK_MAGIC;
|
||||
|
||||
TORRENT_ASSERT(is_open());
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
// if the sockets are closed, the udp_socket is closing too
|
||||
if (!is_open()) return;
|
||||
if (!is_open())
|
||||
{
|
||||
ec = error_code(boost::system::errc::bad_file_descriptor, boost::system::generic_category());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(flags & peer_connection) || m_proxy_settings.proxy_peer_connections)
|
||||
{
|
||||
|
@ -675,7 +681,11 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
|
|||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
TORRENT_ASSERT(m_abort == false);
|
||||
if (m_abort) return;
|
||||
if (m_abort)
|
||||
{
|
||||
ec = boost::asio::error::operation_aborted;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_ipv4_sock.is_open()) m_ipv4_sock.close(ec);
|
||||
#if TORRENT_USE_IPV6
|
||||
|
@ -714,48 +724,6 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
|
|||
m_bind_port = ep.port();
|
||||
}
|
||||
|
||||
void udp_socket::bind(int port)
|
||||
{
|
||||
CHECK_MAGIC;
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
TORRENT_ASSERT(m_abort == false);
|
||||
if (m_abort) return;
|
||||
|
||||
error_code ec;
|
||||
|
||||
if (m_ipv4_sock.is_open()) m_ipv4_sock.close(ec);
|
||||
#if TORRENT_USE_IPV6
|
||||
if (m_ipv6_sock.is_open()) m_ipv6_sock.close(ec);
|
||||
#endif
|
||||
|
||||
if (m_abort) return;
|
||||
|
||||
m_ipv4_sock.open(udp::v4(), ec);
|
||||
if (!ec)
|
||||
{
|
||||
m_ipv4_sock.bind(udp::endpoint(address_v4::any(), port), ec);
|
||||
setup_read(&m_ipv4_sock);
|
||||
}
|
||||
#if TORRENT_USE_IPV6
|
||||
m_ipv6_sock.open(udp::v6(), ec);
|
||||
if (!ec)
|
||||
{
|
||||
#ifdef IPV6_V6ONLY
|
||||
m_ipv6_sock.set_option(v6only(true), ec);
|
||||
#endif
|
||||
m_ipv6_sock.bind(udp::endpoint(address_v6::any(), port), ec);
|
||||
|
||||
setup_read(&m_ipv6_sock);
|
||||
}
|
||||
#endif // TORRENT_USE_IPV6
|
||||
|
||||
#ifdef TORRENT_DEBUG
|
||||
m_started = true;
|
||||
#endif
|
||||
m_bind_port = port;
|
||||
}
|
||||
|
||||
void udp_socket::set_proxy_settings(proxy_settings const& ps)
|
||||
{
|
||||
CHECK_MAGIC;
|
||||
|
|
Loading…
Reference in New Issue