DeviceUsedPortsGatherer: Move getNextFreePort() into PortList

Seems more natural place for this function.

Change-Id: I09f6776ce946f623e3a512411bb922841c06a47d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2022-10-14 14:59:54 +02:00
parent 8394bb0a2b
commit 8f9d582c6c
4 changed files with 13 additions and 13 deletions

View File

@@ -168,6 +168,16 @@ Port PortList::getNext()
return next;
}
Port PortList::getNextFreePort(const QList<Port> &usedPorts)
{
while (hasMore()) {
const Port port = getNext();
if (!usedPorts.contains(port))
return port;
}
return {};
}
QString PortList::toString() const
{
QString stringRep;

View File

@@ -28,6 +28,7 @@ public:
bool contains(Port port) const;
int count() const;
Port getNext();
Port getNextFreePort(const QList<Port> &usedPorts);
QString toString() const;
static PortList fromString(const QString &portsSpec);

View File

@@ -19,7 +19,7 @@ namespace Internal {
class DeviceUsedPortsGathererPrivate
{
public:
public:
std::unique_ptr<QtcProcess> process;
QList<Port> 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<Port> 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;
}

View File

@@ -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<Utils::Port> usedPorts() const;
signals: