From eb007b24cdb7b6db2f42fd92ecb4657b1bd8f48c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 6 Sep 2016 11:55:19 -0700 Subject: [PATCH] Use invalid port to signal no value passed --- domain-server/src/DomainServer.cpp | 4 ++-- interface/src/Application.cpp | 6 ++---- libraries/networking/src/LimitedNodeList.cpp | 6 +++--- libraries/networking/src/LimitedNodeList.h | 8 +++++--- libraries/networking/src/NodeList.cpp | 2 +- libraries/networking/src/NodeList.h | 8 ++++---- tests/render-perf/src/main.cpp | 2 +- tests/render-texture-load/src/main.cpp | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index b61fef8525..0c8296bb00 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -368,11 +368,11 @@ void DomainServer::setupNodeListAndAssignments() { const QString CUSTOM_LOCAL_PORT_OPTION = "metaverse.local_port"; QVariant localPortValue = _settingsManager.valueOrDefaultValueForKeyPath(CUSTOM_LOCAL_PORT_OPTION); - unsigned short domainServerPort = (unsigned short) localPortValue.toUInt(); + int domainServerPort = localPortValue.toInt(); QVariantMap& settingsMap = _settingsManager.getSettingsMap(); - unsigned short domainServerDTLSPort = 0; + int domainServerDTLSPort = INVALID_PORT; if (_isUsingDTLS) { domainServerDTLSPort = DEFAULT_DOMAIN_SERVER_DTLS_PORT; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 45feed1088..92309fd7f9 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -401,12 +401,10 @@ static const QString STATE_GROUNDED = "Grounded"; static const QString STATE_NAV_FOCUSED = "NavigationFocused"; bool setupEssentials(int& argc, char** argv) { - unsigned int listenPort = 0; // bind to an ephemeral port by default const char** constArgv = const_cast(argv); const char* portStr = getCmdOption(argc, constArgv, "--listenPort"); - if (portStr) { - listenPort = atoi(portStr); - } + const int listenPort = portStr ? atoi(portStr) : INVALID_PORT; + // Set build version QCoreApplication::setApplicationVersion(BuildInfo::VERSION); diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 9cf7d87fb5..7fad66d608 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -43,7 +43,7 @@ const std::set SOLO_NODE_TYPES = { NodeType::AudioMixer }; -LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short dtlsListenPort) : +LimitedNodeList::LimitedNodeList(int socketListenPort, int dtlsListenPort) : _sessionUUID(), _nodeHash(), _nodeMutex(QReadWriteLock::Recursive), @@ -66,11 +66,11 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short } qRegisterMetaType("ConnectionStep"); - auto port = (socketListenPort != 0) ? socketListenPort : LIMITED_NODELIST_LOCAL_PORT.get(); + auto port = (socketListenPort != INVALID_PORT) ? socketListenPort : LIMITED_NODELIST_LOCAL_PORT.get(); _nodeSocket.bind(QHostAddress::AnyIPv4, port); qCDebug(networking) << "NodeList socket is listening on" << _nodeSocket.localPort(); - if (dtlsListenPort > 0) { + if (dtlsListenPort != INVALID_PORT) { // only create the DTLS socket during constructor if a custom port is passed _dtlsSocket = new QUdpSocket(this); diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 11df4a8f04..cd343a5232 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -45,6 +45,8 @@ #include "udt/Socket.h" #include "UUIDHasher.h" +const int INVALID_PORT = -1; + const quint64 NODE_SILENCE_THRESHOLD_MSECS = 5 * 1000; extern const std::set SOLO_NODE_TYPES; @@ -270,9 +272,9 @@ protected slots: void errorTestingLocalSocket(); protected: - LimitedNodeList(unsigned short socketListenPort = 0, unsigned short dtlsListenPort = 0); - LimitedNodeList(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton - void operator=(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton + LimitedNodeList(int socketListenPort = INVALID_PORT, int dtlsListenPort = INVALID_PORT); + LimitedNodeList(LimitedNodeList const&) = delete; // Don't implement, needed to avoid copies of singleton + void operator=(LimitedNodeList const&) = delete; // Don't implement, needed to avoid copies of singleton qint64 sendPacket(std::unique_ptr packet, const Node& destinationNode, const HifiSockAddr& overridenSockAddr); diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 6269499e28..593a79b311 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -33,7 +33,7 @@ const int KEEPALIVE_PING_INTERVAL_MS = 1000; -NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned short dtlsListenPort) : +NodeList::NodeList(char newOwnerType, int socketListenPort, int dtlsListenPort) : LimitedNodeList(socketListenPort, dtlsListenPort), _ownerType(newOwnerType), _nodeTypesOfInterest(), diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index f3cd5bed0d..f08c0dbe45 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -116,10 +116,10 @@ private slots: void maybeSendIgnoreSetToNode(SharedNodePointer node); private: - NodeList() : LimitedNodeList(0, 0) { assert(false); } // Not implemented, needed for DependencyManager templates compile - NodeList(char ownerType, unsigned short socketListenPort = 0, unsigned short dtlsListenPort = 0); - NodeList(NodeList const&); // Don't implement, needed to avoid copies of singleton - void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton + NodeList() : LimitedNodeList(INVALID_PORT, INVALID_PORT) { assert(false); } // Not implemented, needed for DependencyManager templates compile + NodeList(char ownerType, int socketListenPort = INVALID_PORT, int dtlsListenPort = INVALID_PORT); + NodeList(NodeList const&) = delete; // Don't implement, needed to avoid copies of singleton + void operator=(NodeList const&) = delete; // Don't implement, needed to avoid copies of singleton void processDomainServerAuthRequest(const QByteArray& packet); void requestAuthForDomainServer(); diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index c6cca74c69..7fa36136d2 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -503,7 +503,7 @@ public: DependencyManager::registerInheritance(); DependencyManager::registerInheritance(); DependencyManager::set(); - DependencyManager::set(NodeType::Agent, 0); + DependencyManager::set(NodeType::Agent); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); diff --git a/tests/render-texture-load/src/main.cpp b/tests/render-texture-load/src/main.cpp index fd6885c381..04bce72757 100644 --- a/tests/render-texture-load/src/main.cpp +++ b/tests/render-texture-load/src/main.cpp @@ -295,7 +295,7 @@ public: DependencyManager::registerInheritance(); //DependencyManager::registerInheritance(); DependencyManager::set(); - DependencyManager::set(NodeType::Agent, 0); + DependencyManager::set(NodeType::Agent); DependencyManager::set(); DependencyManager::set(); DependencyManager::set();