Code optimization

Made code to listen on a particular interface more robust
This commit is contained in:
Christophe Dumez 2010-10-30 22:40:28 +00:00
commit 6c1eda8755
2 changed files with 36 additions and 61 deletions

View file

@ -197,14 +197,6 @@ void QBtSession::preAllocateAllFiles(bool b) {
}
}
ScanFoldersModel* QBtSession::getScanFoldersModel() const {
return m_scanFolders;
}
bool QBtSession::isPexEnabled() const {
return PeXEnabled;
}
void QBtSession::processBigRatios() {
if(ratio_limit < 0) return;
qDebug("Process big ratios...");
@ -243,10 +235,6 @@ void QBtSession::setDownloadLimit(QString hash, long val) {
}
}
bool QBtSession::isQueueingEnabled() const {
return queueingEnabled;
}
void QBtSession::setUploadLimit(QString hash, long val) {
qDebug("Set upload limit rate to %ld", val);
QTorrentHandle h = getTorrentHandle(hash);
@ -1358,15 +1346,6 @@ void QBtSession::setMaxUploadsPerTorrent(int max) {
}
}
// Return DHT state
bool QBtSession::isDHTEnabled() const{
return DHTEnabled;
}
bool QBtSession::isLSDEnabled() const{
return LSDEnabled;
}
void QBtSession::enableUPnP(bool b) {
if(b) {
if(!UPnPEnabled) {
@ -1605,14 +1584,6 @@ void QBtSession::saveFastResumeData() {
}
}
QStringList QBtSession::getConsoleMessages() const {
return consoleMessages;
}
QStringList QBtSession::getPeerBanMessages() const {
return peerBanMessages;
}
#ifdef DISABLE_GUI
void QBtSession::addConsoleMessage(QString msg, QString) {
#else
@ -1666,14 +1637,6 @@ void QBtSession::addTorrentsFromScanFolder(QStringList &pathList) {
}
}
QString QBtSession::getDefaultSavePath() const {
return defaultSavePath;
}
bool QBtSession::useTemporaryFolder() const {
return !defaultTempPath.isEmpty();
}
void QBtSession::setDefaultTempPath(QString temppath) {
if(defaultTempPath == temppath)
return;
@ -1808,15 +1771,27 @@ void QBtSession::setListeningPort(int port) {
}
QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name);
if(!network_iface.isValid()) {
qDebug("Invalid network interface: %s", qPrintable(iface_name));
addConsoleMessage(tr("The network interface defined is invalid: %1").arg(iface_name), "red");
addConsoleMessage(tr("Trying any other network interface available instead."));
s->listen_on(ports);
return;
}
QString ip = "127.0.0.1";
if(!network_iface.addressEntries().isEmpty()) {
ip = network_iface.addressEntries().first().ip().toString();
QString ip;
qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size());
foreach(const QNetworkAddressEntry &entry, network_iface.addressEntries()) {
qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name));
if(s->listen_on(ports, qPrintable(entry.ip().toString()))) {
ip = entry.ip().toString();
break;
}
}
if(s->is_listening()) {
addConsoleMessage(tr("Listening on IP address %1 on network interface %2...").arg(ip).arg(iface_name));
} else {
qDebug("Failed to listen on any of the IP addresses");
addConsoleMessage(tr("Failed to listen on network interface %1").arg(iface_name), "red");
}
qDebug("Listening on interface %s with ip %s", qPrintable(iface_name), qPrintable(ip));
s->listen_on(ports, ip.toLocal8Bit().constData());
}
// Set download rate limit
@ -1827,10 +1802,6 @@ void QBtSession::setDownloadRateLimit(long rate) {
s->set_download_rate_limit(rate);
}
session* QBtSession::getSession() const{
return s;
}
// Set upload rate limit
// -1 to disable
void QBtSession::setUploadRateLimit(long rate) {