From 122db6a77e2e0ca00d594a47cbbac0520e3402f8 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 5 May 2011 16:16:20 +0000 Subject: [PATCH] Fix exceptions on Windows XP when IPv6 is disabled (Thanks paolo zambotti) --- src/properties/peerlistwidget.cpp | 4 +++- src/qtlibtorrent/qbtsession.cpp | 19 ++++++++++++++----- src/reverseresolution.h | 8 ++++++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/properties/peerlistwidget.cpp b/src/properties/peerlistwidget.cpp index e540b680f..570bf5f24 100644 --- a/src/properties/peerlistwidget.cpp +++ b/src/properties/peerlistwidget.cpp @@ -288,13 +288,15 @@ void PeerListWidget::saveSettings() const { void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_resolution) { if(!h.is_valid()) return; + boost::system::error_code ec; std::vector peers; h.get_peer_info(peers); std::vector::iterator itr; QSet old_peers_set = peerItems.keys().toSet(); for(itr = peers.begin(); itr != peers.end(); itr++) { peer_info peer = *itr; - QString peer_ip = misc::toQString(peer.ip.address().to_string()); + QString peer_ip = misc::toQString(peer.ip.address().to_string(ec)); + if(ec) continue; if(peerItems.contains(peer_ip)) { // Update existing peer updatePeer(peer_ip, peer); diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 2de2fcd0a..7ad085a2f 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -2505,12 +2505,20 @@ void QBtSession::readAlerts() { //emit UPnPSuccess(QString(p->msg().c_str())); } else if (peer_blocked_alert* p = dynamic_cast(a.get())) { - addPeerBanMessage(QString(p->ip.to_string().c_str()), true); - //emit peerBlocked(QString::fromUtf8(p->ip.to_string().c_str())); + boost::system::error_code ec; + string ip = p->ip.to_string(ec); + if (!ec) { + addPeerBanMessage(QString::fromAscii(ip.c_str()), true); + //emit peerBlocked(QString::fromAscii(ip.c_str())); + } } else if (peer_ban_alert* p = dynamic_cast(a.get())) { - addPeerBanMessage(QString(p->ip.address().to_string().c_str()), false); - //emit peerBlocked(QString::fromUtf8(p->ip.to_string().c_str())); + boost::system::error_code ec; + string ip = p->ip.address().to_string(ec); + if (!ec) { + addPeerBanMessage(QString::fromAscii(ip.c_str()), false); + //emit peerBlocked(QString::fromAscii(ip.c_str())); + } } else if (fastresume_rejected_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); @@ -2538,7 +2546,8 @@ void QBtSession::readAlerts() { //emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str())); } else if (listen_succeeded_alert *p = dynamic_cast(a.get())) { - qDebug() << "Sucessfully listening on" << p->endpoint.address().to_string().c_str() << "/" << p->endpoint.port(); + boost::system::error_code ec; + qDebug() << "Sucessfully listening on" << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port(); // Force reannounce on all torrents because some trackers blacklist some ports std::vector torrents = s->get_torrents(); std::vector::iterator it; diff --git a/src/reverseresolution.h b/src/reverseresolution.h index e0f2e57e9..8c4377383 100644 --- a/src/reverseresolution.h +++ b/src/reverseresolution.h @@ -60,7 +60,9 @@ public: } QString getHostFromCache(const libtorrent::asio::ip::tcp::endpoint &ip) { - const QString ip_str = misc::toQString(ip.address().to_string()); + boost::system::error_code ec; + const QString ip_str = misc::toQString(ip.address().to_string(ec)); + if (ec) return QString(); QString ret; if(m_cache.contains(ip_str)) { qDebug("Got host name from cache"); @@ -72,7 +74,9 @@ public: } void resolve(const libtorrent::asio::ip::tcp::endpoint &ip) { - const QString ip_str = misc::toQString(ip.address().to_string()); + boost::system::error_code ec; + const QString ip_str = misc::toQString(ip.address().to_string(ec)); + if (ec) return; if(m_cache.contains(ip_str)) { qDebug("Resolved host name using cache"); emit ip_resolved(ip_str, *m_cache.object(ip_str));