summaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
authorRainer Keller <rainer.keller@digia.com>2013-04-17 13:28:36 +0200
committerRainer Keller <rainer.keller@digia.com>2013-04-17 13:28:36 +0200
commitc47a4ed04da4d8d8f618187f671ed8dcb4ae824a (patch)
tree8831331988aa97f0e97623377df5076d8ece6a46 /main.cpp
parent1312d95b33edc640046abe519f2b6be464ddb6d7 (diff)
Parse extended portlist
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/main.cpp b/main.cpp
index c7e1b62..5ab493a 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,4 +1,5 @@
#include "process.h"
+#include "portlist.h"
#include <QCoreApplication>
#include <QTcpServer>
#include <QProcess>
@@ -95,13 +96,13 @@ static void stop()
connectSocket();
}
-static int findFirstFreePort(int start, int end)
+static int findFirstFreePort(Utils::PortList range)
{
QTcpServer s;
- for (; start <= end; start++) {
- if (s.listen(QHostAddress::Any, start))
- return start;
+ while (range.hasMore()) {
+ if (s.listen(QHostAddress::Any, range.getNext()))
+ return s.serverPort();
}
return -1;
}
@@ -134,30 +135,24 @@ int main(int argc, char **argv)
}
defaultArgs.append(args);
break;
- } else if (args[0] == "--start-debug") {
+ } else if (args[0] == "--debug") {
debug = true;
- if (args.size() < 4) {
- qWarning("--start-debug requires arguments: start-port-range end-port-range and executable");
+ if (args.size() < 3) {
+ qWarning("--debug requires arguments: port-range and executable");
return 1;
}
- int range_start = args[1].toUInt();
- int range_end = args[2].toUInt();
- binary = args[3];
+ Utils::PortList range = Utils::PortList::fromString(args[1]);
+ binary = args[2];
args.removeFirst();
args.removeFirst();
- args.removeFirst();
- if (range_start == 0 || range_end == 0 || range_start > range_end) {
- qWarning("Invalid port range");
- return 1;
- }
if (binary.isEmpty()) {
qWarning("App path is empty");
return 1;
}
- int port = findFirstFreePort(range_start, range_end);
+ int port = findFirstFreePort(range);
if (port < 0) {
- qWarning("Could not find an unsued port in range");
+ qWarning("Could not find an unused port in range");
return 1;
}
defaultArgs.push_front("localhost:" + QString::number(port));