merged i2p_alert fix from RC_0_16

This commit is contained in:
Arvid Norberg 2014-03-15 22:20:19 +00:00
parent 826417b471
commit 6f82d3b8ae
4 changed files with 26 additions and 2 deletions

View File

@ -2041,6 +2041,21 @@ namespace libtorrent
std::string salt;
boost::uint64_t seq;
};
// this alert is used to report errors in the i2p SAM connection
struct TORRENT_EXPORT i2p_alert : alert
{
i2p_alert(error_code const& ec) : error(ec) {}
TORRENT_DEFINE_ALERT(i2p_alert);
const static int static_category = alert::error_notification;
virtual std::string message() const;
// the error that occurred in the i2p SAM connection
error_code error;
};
#undef TORRENT_DEFINE_ALERT
}

View File

@ -610,6 +610,13 @@ namespace libtorrent {
return msg;
}
std::string i2p_alert::message() const
{
char msg[600];
snprintf(msg, sizeof(msg), "i2p_error: [%s] %s"
, error.category().name(), convert_from_native(error.message()).c_str());
return msg;
}
} // namespace libtorrent

View File

@ -148,8 +148,7 @@ namespace libtorrent
void i2p_connection::async_name_lookup(char const* name
, i2p_connection::name_lookup_handler handler)
{
// TORRENT_ASSERT(is_open());
if (m_state == sam_idle && m_name_lookup.empty())
if (m_state == sam_idle && m_name_lookup.empty() && is_open())
do_name_lookup(name, handler);
else
m_name_lookup.push_back(std::make_pair(std::string(name), handler));

View File

@ -2455,6 +2455,9 @@ retry:
{
if (ec)
{
if (m_alerts.should_post<i2p_alert>())
m_alerts.post_alert(i2p_alert(ec));
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
char msg[200];
snprintf(msg, sizeof(msg), "i2p open failed (%d) %s", ec.value(), ec.message().c_str());