added error checking to endpoint to string conversion. fixes problem on systems without IPv6 support
This commit is contained in:
parent
3b6aee6d86
commit
6ce8d367a4
|
@ -98,13 +98,18 @@ namespace libtorrent
|
||||||
|
|
||||||
typedef asio::basic_deadline_timer<libtorrent::ptime> deadline_timer;
|
typedef asio::basic_deadline_timer<libtorrent::ptime> deadline_timer;
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& os, tcp::endpoint const& ep)
|
inline std::ostream& print_endpoint(std::ostream& os, tcp::endpoint const& ep)
|
||||||
{
|
{
|
||||||
address const& a = ep.address();
|
address const& addr = ep.address();
|
||||||
if (a.is_v6())
|
asio::error_code ec;
|
||||||
os << "[" << a.to_string() << "]:" << ep.port();
|
std::string a = addr.to_string(ec);
|
||||||
|
if (ec) return os;
|
||||||
|
|
||||||
|
if (addr.is_v6())
|
||||||
|
os << "[" << a << "]:";
|
||||||
else
|
else
|
||||||
os << a.to_string() << ":" << ep.port();
|
os << a << ":";
|
||||||
|
os << ep.port();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -695,14 +695,16 @@ namespace detail
|
||||||
// not even that worked, give up
|
// not even that worked, give up
|
||||||
if (m_alerts.should_post(alert::fatal))
|
if (m_alerts.should_post(alert::fatal))
|
||||||
{
|
{
|
||||||
std::string msg = "cannot bind to the given interface '"
|
std::stringstream msg;
|
||||||
+ boost::lexical_cast<std::string>(ep) + "' " + ec.message();
|
msg << "cannot bind to interface '";
|
||||||
m_alerts.post_alert(listen_failed_alert(ep, msg));
|
print_endpoint(msg, ep) << "' " << ec.message();
|
||||||
|
m_alerts.post_alert(listen_failed_alert(ep, msg.str()));
|
||||||
}
|
}
|
||||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||||
std::string msg = "cannot bind to the given interface '"
|
std::stringstream msg;
|
||||||
+ boost::lexical_cast<std::string>(ep) + "' " + ec.message();
|
msg << "cannot bind to interface '";
|
||||||
(*m_logger) << msg << "\n";
|
print_endpoint(msg, ep) << "' " << ec.message();
|
||||||
|
(*m_logger) << msg.str() << "\n";
|
||||||
#endif
|
#endif
|
||||||
return listen_socket_t();
|
return listen_socket_t();
|
||||||
}
|
}
|
||||||
|
@ -712,14 +714,16 @@ namespace detail
|
||||||
{
|
{
|
||||||
if (m_alerts.should_post(alert::fatal))
|
if (m_alerts.should_post(alert::fatal))
|
||||||
{
|
{
|
||||||
std::string msg = "cannot listen the given interface '"
|
std::stringstream msg;
|
||||||
+ boost::lexical_cast<std::string>(ep) + "' " + ec.message();
|
msg << "cannot listen on interface '";
|
||||||
m_alerts.post_alert(listen_failed_alert(ep, msg));
|
print_endpoint(msg, ep) << "' " << ec.message();
|
||||||
|
m_alerts.post_alert(listen_failed_alert(ep, msg.str()));
|
||||||
}
|
}
|
||||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||||
std::string msg = "cannot listen the given interface '"
|
std::stringstream msg;
|
||||||
+ boost::lexical_cast<std::string>(ep) + "' " + ec.message();
|
msg << "cannot listen on interface '";
|
||||||
(*m_logger) << msg << "\n";
|
print_endpoint(msg, ep) << "' " << ec.message();
|
||||||
|
(*m_logger) << msg.str() << "\n";
|
||||||
#endif
|
#endif
|
||||||
return listen_socket_t();
|
return listen_socket_t();
|
||||||
}
|
}
|
||||||
|
@ -732,7 +736,7 @@ namespace detail
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||||
(*m_logger) << "listening on: " << ep.address().to_string() << ":" << ep.port()
|
(*m_logger) << "listening on: " << ep
|
||||||
<< " external port: " << s.external_port << "\n";
|
<< " external port: " << s.external_port << "\n";
|
||||||
#endif
|
#endif
|
||||||
return s;
|
return s;
|
||||||
|
|
Loading…
Reference in New Issue