Merge branch 'atp' of https://github.com/birarda/hifi into protocol

This commit is contained in:
Atlante45 2015-07-14 17:30:55 -07:00
commit 1db1180869
3 changed files with 34 additions and 61 deletions

View file

@ -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 <QDebug>
#include <HifiSockAddr.h>
#include <NodeList.h>
#include <udt/PacketHeaders.h>
#include <SharedUtil.h>
#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<NodeList>()->processNodeData(senderSockAddr, incomingPacket);
return; // don't emit
}
// emit the signal to tell AudioMixer it needs to process a packet
emit packetRequiresProcessing(incomingPacket, senderSockAddr);
}
}

View file

@ -30,7 +30,11 @@ qint64 NLPacket::localHeaderSize() const {
}
std::unique_ptr<NLPacket> NLPacket::create(PacketType::Value type, qint64 size) {
return std::unique_ptr<NLPacket>(new NLPacket(type, size));
auto packet = std::unique_ptr<NLPacket>(new NLPacket(type, size));
packet->open(QIODevice::WriteOnly);
return packet;
}
std::unique_ptr<NLPacket> NLPacket::fromReceivedPacket(std::unique_ptr<char> data, qint64 size,
@ -42,12 +46,22 @@ std::unique_ptr<NLPacket> NLPacket::fromReceivedPacket(std::unique_ptr<char> dat
Q_ASSERT(size >= 0);
// allocate memory
return std::unique_ptr<NLPacket>(new NLPacket(std::move(data), size, senderSockAddr));
auto packet = std::unique_ptr<NLPacket>(new NLPacket(std::move(data), size, senderSockAddr));
packet->open(QIODevice::ReadOnly);
return packet;
}
std::unique_ptr<NLPacket> NLPacket::createCopy(const NLPacket& other) {
return std::unique_ptr<NLPacket>(new NLPacket(other));
auto packet = std::unique_ptr<NLPacket>(new NLPacket(other));
if (other.isOpen()) {
packet->open(other.openMode());
}
return packet;
}
NLPacket::NLPacket(PacketType::Value type, qint64 size) : Packet(type, localHeaderSize(type) + size) {

View file

@ -22,7 +22,11 @@ qint64 Packet::maxPayloadSize(PacketType::Value type) {
}
std::unique_ptr<Packet> Packet::create(PacketType::Value type, qint64 size) {
return std::unique_ptr<Packet>(new Packet(type, size));
auto packet = std::unique_ptr<Packet>(new Packet(type, size));
packet->open(QIODevice::WriteOnly);
return packet;
}
std::unique_ptr<Packet> Packet::fromReceivedPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& senderSockAddr) {
@ -30,11 +34,21 @@ std::unique_ptr<Packet> Packet::fromReceivedPacket(std::unique_ptr<char> data, q
Q_ASSERT(size >= 0);
// allocate memory
return std::unique_ptr<Packet>(new Packet(std::move(data), size, senderSockAddr));
auto packet = std::unique_ptr<Packet>(new Packet(std::move(data), size, senderSockAddr));
packet->open(QIODevice::ReadOnly);
return packet;
}
std::unique_ptr<Packet> Packet::createCopy(const Packet& other) {
return std::unique_ptr<Packet>(new Packet(other));
auto packet = std::unique_ptr<Packet>(new Packet(other));
if (other.isOpen()) {
packet->open(other.openMode());
}
return packet;
}
qint64 Packet::totalHeadersSize() const {