get free port that can be used by non root users (> 1024)

This commit is contained in:
Benjamin Sergeant 2019-01-28 15:23:33 -08:00
parent ae841af91a
commit 6a23b8530f

View File

@ -69,7 +69,7 @@ namespace ix
Logger() << msg;
}
int getFreePort()
int getAnyFreePort()
{
int defaultPort = 8090;
@ -117,4 +117,23 @@ namespace ix
return port;
}
int getFreePort()
{
while (true)
{
int port = getAnyFreePort();
//
// Only port above 1024 can be used by non root users, but for some
// reason I got port 7 returned with macOS when binding on port 0...
//
if (port > 1024)
{
return port;
}
}
return -1;
}
}