forked from qt-creator/qt-creator
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:
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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:
|
||||
|
Reference in New Issue
Block a user