From 019d234ffd3e99ceca4a1c5c728e14a80357a7a7 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 1 Sep 2015 11:55:26 -0700 Subject: [PATCH 1/5] Replace std::bind for methods that use std::unique_ptr with a lambda --- ice-server/src/IceServer.cpp | 2 +- libraries/networking/src/LimitedNodeList.cpp | 6 +++--- tools/udt-test/src/UDTTest.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index a2603269d9..a44b6393de 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -36,7 +36,7 @@ IceServer::IceServer(int argc, char* argv[]) : // set processPacket as the verified packet callback for the udt::Socket using std::placeholders::_1; - _serverSocket.setPacketHandler(std::bind(&IceServer::processPacket, this, _1)); + _serverSocket.setPacketHandler([this](std::unique_ptr packet) { processPacket(std::move(packet)); }); // set packetVersionMatch as the verify packet operator for the udt::Socket _serverSocket.setPacketFilterOperator(std::bind(&IceServer::packetVersionMatch, this, _1)); diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 2d1c98287c..74d922ce67 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -95,8 +95,8 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short // set &PacketReceiver::handleVerifiedPacket as the verified packet callback for the udt::Socket using std::placeholders::_1; - _nodeSocket.setPacketHandler(std::bind(&PacketReceiver::handleVerifiedPacket, _packetReceiver, _1)); - _nodeSocket.setPacketListHandler(std::bind(&PacketReceiver::handleVerifiedPacketList, _packetReceiver, _1)); + _nodeSocket.setPacketHandler([this](std::unique_ptr packet) { _packetReceiver->handleVerifiedPacket(std::move(packet)); }); + _nodeSocket.setPacketListHandler([this](std::unique_ptr packetList) { _packetReceiver->handleVerifiedPacketList(std::move(packetList)); }); // set our isPacketVerified method as the verify operator for the udt::Socket _nodeSocket.setPacketFilterOperator(std::bind(&LimitedNodeList::isPacketVerified, this, _1)); @@ -764,7 +764,7 @@ void LimitedNodeList::possiblyTimeoutSTUNAddressLookup() { void LimitedNodeList::addSTUNHandlerToUnfiltered() { // make ourselves the handler of STUN packets when they come in using std::placeholders::_1; - _nodeSocket.addUnfilteredHandler(_stunSockAddr, std::bind(&LimitedNodeList::processSTUNResponse, this, _1)); + _nodeSocket.addUnfilteredHandler(_stunSockAddr, [this](std::unique_ptr packet) { processSTUNResponse(std::move(packet)); }); } void LimitedNodeList::stopInitialSTUNUpdate(bool success) { diff --git a/tools/udt-test/src/UDTTest.cpp b/tools/udt-test/src/UDTTest.cpp index f11ff0d489..d8d20436b4 100644 --- a/tools/udt-test/src/UDTTest.cpp +++ b/tools/udt-test/src/UDTTest.cpp @@ -177,7 +177,7 @@ UDTTest::UDTTest(int& argc, char** argv) : // this is a receiver - in case there are ordered packets (messages) being sent to us make sure that we handle them // so that they can be verified using std::placeholders::_1; - _socket.setPacketListHandler(std::bind(&UDTTest::handlePacketList, this, _1)); + _socket.setPacketListHandler([this](std::unique_ptr packetList) { handlePacketList(std::move(packetList)); }); } // the sender reports stats every 100 milliseconds, unless passed a custom value From cb5a49e6e4561bea153ea2453e7feec7b02577c0 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 1 Sep 2015 11:59:45 -0700 Subject: [PATCH 2/5] Add missing headers needed to build on Windows --- libraries/networking/src/HifiSockAddr.h | 1 + libraries/networking/src/ResourceRequest.h | 2 ++ libraries/networking/src/udt/BasePacket.h | 4 ++++ libraries/networking/src/udt/CongestionControl.h | 1 + libraries/networking/src/udt/SendQueue.h | 3 +++ 5 files changed, 11 insertions(+) diff --git a/libraries/networking/src/HifiSockAddr.h b/libraries/networking/src/HifiSockAddr.h index c66579eca1..637b9e56ce 100644 --- a/libraries/networking/src/HifiSockAddr.h +++ b/libraries/networking/src/HifiSockAddr.h @@ -12,6 +12,7 @@ #ifndef hifi_HifiSockAddr_h #define hifi_HifiSockAddr_h +#include #include #ifdef WIN32 diff --git a/libraries/networking/src/ResourceRequest.h b/libraries/networking/src/ResourceRequest.h index 0aae013b62..b229951a49 100644 --- a/libraries/networking/src/ResourceRequest.h +++ b/libraries/networking/src/ResourceRequest.h @@ -15,6 +15,8 @@ #include #include +#include + class ResourceRequest : public QObject { Q_OBJECT public: diff --git a/libraries/networking/src/udt/BasePacket.h b/libraries/networking/src/udt/BasePacket.h index 33d4aab6ea..4e13d99013 100644 --- a/libraries/networking/src/udt/BasePacket.h +++ b/libraries/networking/src/udt/BasePacket.h @@ -14,6 +14,8 @@ #ifndef hifi_BasePacket_h #define hifi_BasePacket_h +#include + #include #include "../HifiSockAddr.h" @@ -29,6 +31,8 @@ public: static std::unique_ptr create(qint64 size = -1); static std::unique_ptr fromReceivedPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr); + + // Current level's header size static int localHeaderSize(); diff --git a/libraries/networking/src/udt/CongestionControl.h b/libraries/networking/src/udt/CongestionControl.h index 5208ff9d3b..63baee0e28 100644 --- a/libraries/networking/src/udt/CongestionControl.h +++ b/libraries/networking/src/udt/CongestionControl.h @@ -13,6 +13,7 @@ #define hifi_CongestionControl_h #include +#include #include #include "LossList.h" diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index beb89a77d6..564e74a3fb 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -12,9 +12,12 @@ #ifndef hifi_SendQueue_h #define hifi_SendQueue_h +#include #include #include +#include #include +#include #include #include From d166e6d8c39f1e859afc561293b8ea0389cc2239 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 1 Sep 2015 12:00:43 -0700 Subject: [PATCH 3/5] Move UUID.cpp/h to libraries/shared --- libraries/networking/src/UUID.cpp | 17 ----------------- libraries/networking/src/UUID.h | 21 --------------------- 2 files changed, 38 deletions(-) delete mode 100644 libraries/networking/src/UUID.cpp delete mode 100644 libraries/networking/src/UUID.h diff --git a/libraries/networking/src/UUID.cpp b/libraries/networking/src/UUID.cpp deleted file mode 100644 index eafd7dd181..0000000000 --- a/libraries/networking/src/UUID.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// -// UUID.cpp -// libraries/shared/src -// -// Created by Stephen Birarda on 10/7/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include "UUID.h" - -QString uuidStringWithoutCurlyBraces(const QUuid& uuid) { - QString uuidStringNoBraces = uuid.toString().mid(1, uuid.toString().length() - 2); - return uuidStringNoBraces; -} diff --git a/libraries/networking/src/UUID.h b/libraries/networking/src/UUID.h deleted file mode 100644 index 7e7048486f..0000000000 --- a/libraries/networking/src/UUID.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// UUID.h -// libraries/shared/src -// -// Created by Stephen Birarda on 10/7/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_UUID_h -#define hifi_UUID_h - -#include - -const int NUM_BYTES_RFC4122_UUID = 16; - -QString uuidStringWithoutCurlyBraces(const QUuid& uuid); - -#endif // hifi_UUID_h From fb8e822fa869780169658c311aba3f6cdeba63fd Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 1 Sep 2015 12:14:58 -0700 Subject: [PATCH 4/5] Fix lines longer than 120 columns --- libraries/networking/src/LimitedNodeList.cpp | 12 ++++++++++-- tools/udt-test/src/UDTTest.cpp | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 74d922ce67..4e197a3ee4 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -95,8 +95,16 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short // set &PacketReceiver::handleVerifiedPacket as the verified packet callback for the udt::Socket using std::placeholders::_1; - _nodeSocket.setPacketHandler([this](std::unique_ptr packet) { _packetReceiver->handleVerifiedPacket(std::move(packet)); }); - _nodeSocket.setPacketListHandler([this](std::unique_ptr packetList) { _packetReceiver->handleVerifiedPacketList(std::move(packetList)); }); + _nodeSocket.setPacketHandler( + [this](std::unique_ptr packet) { + _packetReceiver->handleVerifiedPacket(std::move(packet)); + } + ); + _nodeSocket.setPacketListHandler( + [this](std::unique_ptr packetList) { + _packetReceiver->handleVerifiedPacketList(std::move(packetList)); + } + ); // set our isPacketVerified method as the verify operator for the udt::Socket _nodeSocket.setPacketFilterOperator(std::bind(&LimitedNodeList::isPacketVerified, this, _1)); diff --git a/tools/udt-test/src/UDTTest.cpp b/tools/udt-test/src/UDTTest.cpp index d8d20436b4..4b12c97f7c 100644 --- a/tools/udt-test/src/UDTTest.cpp +++ b/tools/udt-test/src/UDTTest.cpp @@ -177,7 +177,8 @@ UDTTest::UDTTest(int& argc, char** argv) : // this is a receiver - in case there are ordered packets (messages) being sent to us make sure that we handle them // so that they can be verified using std::placeholders::_1; - _socket.setPacketListHandler([this](std::unique_ptr packetList) { handlePacketList(std::move(packetList)); }); + _socket.setPacketListHandler( + [this](std::unique_ptr packetList) { handlePacketList(std::move(packetList)); }); } // the sender reports stats every 100 milliseconds, unless passed a custom value From b73d30721032d4cc166ec01c0b489d2e18d77e63 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 1 Sep 2015 12:23:24 -0700 Subject: [PATCH 5/5] Move std::placeholders::_1 to where they are used --- ice-server/src/IceServer.cpp | 2 +- libraries/networking/src/LimitedNodeList.cpp | 3 +-- tools/udt-test/src/UDTTest.cpp | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index a44b6393de..a6a28caa23 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -35,10 +35,10 @@ IceServer::IceServer(int argc, char* argv[]) : _serverSocket.bind(QHostAddress::AnyIPv4, ICE_SERVER_DEFAULT_PORT); // set processPacket as the verified packet callback for the udt::Socket - using std::placeholders::_1; _serverSocket.setPacketHandler([this](std::unique_ptr packet) { processPacket(std::move(packet)); }); // set packetVersionMatch as the verify packet operator for the udt::Socket + using std::placeholders::_1; _serverSocket.setPacketFilterOperator(std::bind(&IceServer::packetVersionMatch, this, _1)); // setup our timer to clear inactive peers diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 4e197a3ee4..e0b35b5773 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -94,7 +94,6 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short updateLocalSockAddr(); // set &PacketReceiver::handleVerifiedPacket as the verified packet callback for the udt::Socket - using std::placeholders::_1; _nodeSocket.setPacketHandler( [this](std::unique_ptr packet) { _packetReceiver->handleVerifiedPacket(std::move(packet)); @@ -107,6 +106,7 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short ); // set our isPacketVerified method as the verify operator for the udt::Socket + using std::placeholders::_1; _nodeSocket.setPacketFilterOperator(std::bind(&LimitedNodeList::isPacketVerified, this, _1)); _packetStatTimer.start(); @@ -771,7 +771,6 @@ void LimitedNodeList::possiblyTimeoutSTUNAddressLookup() { void LimitedNodeList::addSTUNHandlerToUnfiltered() { // make ourselves the handler of STUN packets when they come in - using std::placeholders::_1; _nodeSocket.addUnfilteredHandler(_stunSockAddr, [this](std::unique_ptr packet) { processSTUNResponse(std::move(packet)); }); } diff --git a/tools/udt-test/src/UDTTest.cpp b/tools/udt-test/src/UDTTest.cpp index 4b12c97f7c..9a828ebafb 100644 --- a/tools/udt-test/src/UDTTest.cpp +++ b/tools/udt-test/src/UDTTest.cpp @@ -176,7 +176,6 @@ UDTTest::UDTTest(int& argc, char** argv) : } else { // this is a receiver - in case there are ordered packets (messages) being sent to us make sure that we handle them // so that they can be verified - using std::placeholders::_1; _socket.setPacketListHandler( [this](std::unique_ptr packetList) { handlePacketList(std::move(packetList)); }); }