Make error message reflect the actual ports we use

This commit is contained in:
Albert Vaca 2017-02-14 22:52:24 +01:00
parent 8c6f7582e2
commit 25e0cea373
4 changed files with 11 additions and 7 deletions

View file

@ -84,11 +84,11 @@ void LanLinkProvider::onStart()
qCDebug(KDECONNECT_CORE) << "onStart"; qCDebug(KDECONNECT_CORE) << "onStart";
mTcpPort = PORT; mTcpPort = MIN_PORT;
while (!mServer->listen(bindAddress, mTcpPort)) { while (!mServer->listen(bindAddress, mTcpPort)) {
mTcpPort++; mTcpPort++;
if (mTcpPort > 1764) { //No ports available? if (mTcpPort > MAX_PORT) { //No ports available?
qCritical(KDECONNECT_CORE) << "Error opening a port in range 1714-1764"; qCritical(KDECONNECT_CORE) << "Error opening a port in range" << MIN_PORT << "-" << MAX_PORT;
mTcpPort = 0; mTcpPort = 0;
return; return;
} }

View file

@ -54,7 +54,8 @@ public:
static void configureSslSocket(QSslSocket* socket, const QString& deviceId, bool isDeviceTrusted); static void configureSslSocket(QSslSocket* socket, const QString& deviceId, bool isDeviceTrusted);
static void configureSocket(QSslSocket* socket); static void configureSocket(QSslSocket* socket);
const static quint16 PORT = 1716; const static quint16 MIN_PORT = 1716;
const static quint16 MAX_PORT = 1764;
public Q_SLOTS: public Q_SLOTS:
void onNetworkChange() override; void onNetworkChange() override;

View file

@ -40,11 +40,11 @@ UploadJob::UploadJob(const QSharedPointer<QIODevice>& source, const QString& dev
void UploadJob::start() void UploadJob::start()
{ {
mPort = 1739; mPort = MIN_PORT;
while (!mServer->listen(QHostAddress::Any, mPort)) { while (!mServer->listen(QHostAddress::Any, mPort)) {
mPort++; mPort++;
if (mPort > 1764) { //No ports available? if (mPort > MAX_PORT) { //No ports available?
qCWarning(KDECONNECT_CORE) << "Error opening a port in range 1739-1764 for file transfer"; qCWarning(KDECONNECT_CORE) << "Error opening a port in range" << MIN_PORT << "-" << MAX_PORT;
mPort = 0; mPort = 0;
setError(1); setError(1);
setErrorText(i18n("Couldn't find an available port")); setErrorText(i18n("Couldn't find an available port"));

View file

@ -47,6 +47,9 @@ private:
quint16 mPort; quint16 mPort;
const QString mDeviceId; const QString mDeviceId;
const static quint16 MIN_PORT = 1739;
const static quint16 MAX_PORT = 1764;
private Q_SLOTS: private Q_SLOTS:
void startUploading(); void startUploading();
void newConnection(); void newConnection();