diff --git a/src/libs/utils/portlist.cpp b/src/libs/utils/portlist.cpp index 5456c90f8c3..2421cd30a78 100644 --- a/src/libs/utils/portlist.cpp +++ b/src/libs/utils/portlist.cpp @@ -168,6 +168,16 @@ Port PortList::getNext() return next; } +Port PortList::getNextFreePort(const QList &usedPorts) +{ + while (hasMore()) { + const Port port = getNext(); + if (!usedPorts.contains(port)) + return port; + } + return {}; +} + QString PortList::toString() const { QString stringRep; diff --git a/src/libs/utils/portlist.h b/src/libs/utils/portlist.h index 66691adc6ff..b1d51c898b1 100644 --- a/src/libs/utils/portlist.h +++ b/src/libs/utils/portlist.h @@ -28,6 +28,7 @@ public: bool contains(Port port) const; int count() const; Port getNext(); + Port getNextFreePort(const QList &usedPorts); QString toString() const; static PortList fromString(const QString &portsSpec); diff --git a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp index f8882c1121b..cefbfb02db6 100644 --- a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp +++ b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp @@ -19,7 +19,7 @@ namespace Internal { class DeviceUsedPortsGathererPrivate { - public: +public: std::unique_ptr process; QList usedPorts; QByteArray remoteStdout; @@ -77,16 +77,6 @@ void DeviceUsedPortsGatherer::stop() } } -Port DeviceUsedPortsGatherer::getNextFreePort(PortList *freePorts) const -{ - while (freePorts->hasMore()) { - const Port port = freePorts->getNext(); - if (!d->usedPorts.contains(port)) - return port; - } - return Port(); -} - QList DeviceUsedPortsGatherer::usedPorts() const { return d->usedPorts; @@ -165,7 +155,7 @@ QUrl PortsGatherer::findEndPoint() QUrl result; result.setScheme(urlTcpScheme()); result.setHost(device()->sshParameters().host()); - result.setPort(m_portsGatherer.getNextFreePort(&m_portList).number()); + result.setPort(m_portList.getNextFreePort(m_portsGatherer.usedPorts()).number()); return result; } diff --git a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h index a471249144f..1f65ea00260 100644 --- a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h +++ b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h @@ -26,7 +26,6 @@ public: void start(const IDeviceConstPtr &device); void stop(); - Utils::Port getNextFreePort(Utils::PortList *freePorts) const; // returns -1 if no more are left QList usedPorts() const; signals: