diff --git a/src/core/preferences.cpp b/src/core/preferences.cpp index e58a9ae8b..cf1467c30 100644 --- a/src/core/preferences.cpp +++ b/src/core/preferences.cpp @@ -56,7 +56,7 @@ Preferences* Preferences::m_instance = 0; -Preferences::Preferences() : dirty(false), lock(QReadWriteLock::Recursive) { +Preferences::Preferences() : m_randomPort(rand() % 64512 + 1024), dirty(false), lock(QReadWriteLock::Recursive) { QIniSettings *settings = new QIniSettings; #ifndef Q_OS_MAC QIniSettings *settings_new = new QIniSettings("qBittorrent", "qBittorrent_new"); @@ -537,6 +537,9 @@ void Preferences::setActionOnDblClOnTorrentFn(int act) { // Connection options int Preferences::getSessionPort() const { + QReadLocker locker(&lock); + if (useRandomPort()) + return m_randomPort; return value("Preferences/Connection/PortRangeMin", 6881).toInt(); } diff --git a/src/core/preferences.h b/src/core/preferences.h index 0c3d2d97c..f8adc4b9b 100644 --- a/src/core/preferences.h +++ b/src/core/preferences.h @@ -63,6 +63,7 @@ private: explicit Preferences(); static Preferences* m_instance; QHash m_data; + int m_randomPort; bool dirty; QTimer timer; mutable QReadWriteLock lock; diff --git a/src/core/qtlibtorrent/qbtsession.cpp b/src/core/qtlibtorrent/qbtsession.cpp index 05aff6a20..a8e6c1093 100644 --- a/src/core/qtlibtorrent/qbtsession.cpp +++ b/src/core/qtlibtorrent/qbtsession.cpp @@ -309,9 +309,6 @@ void QBtSession::setQueueingEnabled(bool enable) { void QBtSession::configureSession() { qDebug("Configuring session"); Preferences* const pref = Preferences::instance(); - if (pref->useRandomPort()) { - pref->setSessionPort(rand() % USHRT_MAX + 1025); - } const unsigned short old_listenPort = getListenPort(); const unsigned short new_listenPort = pref->getSessionPort();