From 3bf93063d7327735c5cdfa37e8e00523e14162a8 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Jul 2015 17:22:42 -0700 Subject: [PATCH 1/2] remove the OctreeServerDatagramProcessor --- .../octree/OctreeServerDatagramProcessor.cpp | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 assignment-client/src/octree/OctreeServerDatagramProcessor.cpp diff --git a/assignment-client/src/octree/OctreeServerDatagramProcessor.cpp b/assignment-client/src/octree/OctreeServerDatagramProcessor.cpp deleted file mode 100644 index 084fd13ab5..0000000000 --- a/assignment-client/src/octree/OctreeServerDatagramProcessor.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// -// OctreeServerDatagramProcessor.cpp -// assignment-client/src -// -// Created by Brad Hefta-Gaub on 2014-09-05 -// Copyright 2014 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 - -#include -#include -#include -#include - -#include "OctreeServerDatagramProcessor.h" - -OctreeServerDatagramProcessor::OctreeServerDatagramProcessor(QUdpSocket& nodeSocket, QThread* previousNodeSocketThread) : - _nodeSocket(nodeSocket), - _previousNodeSocketThread(previousNodeSocketThread) -{ - -} - -OctreeServerDatagramProcessor::~OctreeServerDatagramProcessor() { - // return the node socket to its previous thread - _nodeSocket.moveToThread(_previousNodeSocketThread); -} - -void OctreeServerDatagramProcessor::readPendingDatagrams() { - - HifiSockAddr senderSockAddr; - static QByteArray incomingPacket; - - // read everything that is available - while (_nodeSocket.hasPendingDatagrams()) { - incomingPacket.resize(_nodeSocket.pendingDatagramSize()); - - // just get this packet off the stack - _nodeSocket.readDatagram(incomingPacket.data(), incomingPacket.size(), - senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); - - PacketType::Value packetType = packetTypeForPacket(incomingPacket); - if (packetType == PacketType::Ping) { - DependencyManager::get()->processNodeData(senderSockAddr, incomingPacket); - return; // don't emit - } - - // emit the signal to tell AudioMixer it needs to process a packet - emit packetRequiresProcessing(incomingPacket, senderSockAddr); - } -} From 3858e6933fee0e2b2add6cf7832daa4a99d6da39 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Jul 2015 17:30:01 -0700 Subject: [PATCH 2/2] open packets for reading and writing --- libraries/networking/src/NLPacket.cpp | 20 +++++++++++++++++--- libraries/networking/src/udt/Packet.cpp | 20 +++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index 6fa7c73d39..db4322bccd 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -30,7 +30,11 @@ qint64 NLPacket::localHeaderSize() const { } std::unique_ptr NLPacket::create(PacketType::Value type, qint64 size) { - return std::unique_ptr(new NLPacket(type, size)); + auto packet = std::unique_ptr(new NLPacket(type, size)); + + packet->open(QIODevice::WriteOnly); + + return packet; } std::unique_ptr NLPacket::fromReceivedPacket(std::unique_ptr data, qint64 size, @@ -42,12 +46,22 @@ std::unique_ptr NLPacket::fromReceivedPacket(std::unique_ptr dat Q_ASSERT(size >= 0); // allocate memory - return std::unique_ptr(new NLPacket(std::move(data), size, senderSockAddr)); + auto packet = std::unique_ptr(new NLPacket(std::move(data), size, senderSockAddr)); + + packet->open(QIODevice::ReadOnly); + + return packet; } std::unique_ptr NLPacket::createCopy(const NLPacket& other) { - return std::unique_ptr(new NLPacket(other)); + auto packet = std::unique_ptr(new NLPacket(other)); + + if (other.isOpen()) { + packet->open(other.openMode()); + } + + return packet; } NLPacket::NLPacket(PacketType::Value type, qint64 size) : Packet(type, localHeaderSize(type) + size) { diff --git a/libraries/networking/src/udt/Packet.cpp b/libraries/networking/src/udt/Packet.cpp index f24da23edd..55c51d7665 100644 --- a/libraries/networking/src/udt/Packet.cpp +++ b/libraries/networking/src/udt/Packet.cpp @@ -22,7 +22,11 @@ qint64 Packet::maxPayloadSize(PacketType::Value type) { } std::unique_ptr Packet::create(PacketType::Value type, qint64 size) { - return std::unique_ptr(new Packet(type, size)); + auto packet = std::unique_ptr(new Packet(type, size)); + + packet->open(QIODevice::WriteOnly); + + return packet; } std::unique_ptr Packet::fromReceivedPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr) { @@ -30,11 +34,21 @@ std::unique_ptr Packet::fromReceivedPacket(std::unique_ptr data, q Q_ASSERT(size >= 0); // allocate memory - return std::unique_ptr(new Packet(std::move(data), size, senderSockAddr)); + auto packet = std::unique_ptr(new Packet(std::move(data), size, senderSockAddr)); + + packet->open(QIODevice::ReadOnly); + + return packet; } std::unique_ptr Packet::createCopy(const Packet& other) { - return std::unique_ptr(new Packet(other)); + auto packet = std::unique_ptr(new Packet(other)); + + if (other.isOpen()) { + packet->open(other.openMode()); + } + + return packet; } qint64 Packet::totalHeadersSize() const {