even more changes

Signed-off-by: Paulchen-Panther <Paulchen--Panter@gmx.net>
This commit is contained in:
Paulchen-Panther
2018-12-28 18:12:45 +01:00
parent 3700566d10
commit 2a77f6f012
99 changed files with 2610 additions and 673 deletions

34
include/utils/NetUtils.h Normal file
View File

@@ -0,0 +1,34 @@
#pragma once
#include <utils/Logger.h>
#include <QTcpServer>
namespace NetUtils {
///
/// @brief Check if the port is available for listening
/// @param[in/out] port The port to test, will be incremented if port is in use
/// @param log The logger of the caller to print
/// @return True on success else false
///
static const bool portAvailable(quint16& port, Logger* log)
{
const quint16 prevPort = port;
QTcpServer server;
bool corrected = false;
while (!server.listen(QHostAddress::Any, port))
{
corrected = true;
Warning(log,"Port '%d' is already in use, will increment", port);
port ++;
}
server.close();
if(corrected)
{
Warning(log, "The requested Port '%d' was already in use, will use Port '%d' instead", prevPort, port);
return false;
}
return true;
}
}