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;
|
||||
|
||||
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();
|
||||
if (a.is_v6())
|
||||
os << "[" << a.to_string() << "]:" << ep.port();
|
||||
address const& addr = ep.address();
|
||||
asio::error_code ec;
|
||||
std::string a = addr.to_string(ec);
|
||||
if (ec) return os;
|
||||
|
||||
if (addr.is_v6())
|
||||
os << "[" << a << "]:";
|
||||
else
|
||||
os << a.to_string() << ":" << ep.port();
|
||||
os << a << ":";
|
||||
os << ep.port();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
|
|
@ -695,14 +695,16 @@ namespace detail
|
|||
// not even that worked, give up
|
||||
if (m_alerts.should_post(alert::fatal))
|
||||
{
|
||||
std::string msg = "cannot bind to the given interface '"
|
||||
+ boost::lexical_cast<std::string>(ep) + "' " + ec.message();
|
||||
m_alerts.post_alert(listen_failed_alert(ep, msg));
|
||||
std::stringstream msg;
|
||||
msg << "cannot bind to interface '";
|
||||
print_endpoint(msg, ep) << "' " << ec.message();
|
||||
m_alerts.post_alert(listen_failed_alert(ep, msg.str()));
|
||||
}
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
std::string msg = "cannot bind to the given interface '"
|
||||
+ boost::lexical_cast<std::string>(ep) + "' " + ec.message();
|
||||
(*m_logger) << msg << "\n";
|
||||
std::stringstream msg;
|
||||
msg << "cannot bind to interface '";
|
||||
print_endpoint(msg, ep) << "' " << ec.message();
|
||||
(*m_logger) << msg.str() << "\n";
|
||||
#endif
|
||||
return listen_socket_t();
|
||||
}
|
||||
|
@ -712,14 +714,16 @@ namespace detail
|
|||
{
|
||||
if (m_alerts.should_post(alert::fatal))
|
||||
{
|
||||
std::string msg = "cannot listen the given interface '"
|
||||
+ boost::lexical_cast<std::string>(ep) + "' " + ec.message();
|
||||
m_alerts.post_alert(listen_failed_alert(ep, msg));
|
||||
std::stringstream msg;
|
||||
msg << "cannot listen on interface '";
|
||||
print_endpoint(msg, ep) << "' " << ec.message();
|
||||
m_alerts.post_alert(listen_failed_alert(ep, msg.str()));
|
||||
}
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
std::string msg = "cannot listen the given interface '"
|
||||
+ boost::lexical_cast<std::string>(ep) + "' " + ec.message();
|
||||
(*m_logger) << msg << "\n";
|
||||
std::stringstream msg;
|
||||
msg << "cannot listen on interface '";
|
||||
print_endpoint(msg, ep) << "' " << ec.message();
|
||||
(*m_logger) << msg.str() << "\n";
|
||||
#endif
|
||||
return listen_socket_t();
|
||||
}
|
||||
|
@ -732,7 +736,7 @@ namespace detail
|
|||
}
|
||||
|
||||
#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";
|
||||
#endif
|
||||
return s;
|
||||
|
|
Loading…
Reference in New Issue