mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 16:38:27 +02:00
remove NetworkPacket and replace with NodePacketPair
This commit is contained in:
parent
30840422ad
commit
6c6143f21e
9 changed files with 59 additions and 151 deletions
|
@ -15,7 +15,6 @@
|
|||
#define hifi_OctreeSendThread_h
|
||||
|
||||
#include <GenericThread.h>
|
||||
#include <NetworkPacket.h>
|
||||
#include <OctreeElementBag.h>
|
||||
|
||||
#include "OctreeQueryNode.h"
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <EntityEditPacketSender.h>
|
||||
#include <EntityTreeRenderer.h>
|
||||
#include <GeometryCache.h>
|
||||
#include <NetworkPacket.h>
|
||||
#include <NodeList.h>
|
||||
#include <OctreeQuery.h>
|
||||
#include <OffscreenUi.h>
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
//
|
||||
// NetworkPacket.cpp
|
||||
// libraries/networking/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/9/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 <cassert>
|
||||
#include <cstring>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "SharedUtil.h"
|
||||
#include "NetworkLogging.h"
|
||||
|
||||
#include "NetworkPacket.h"
|
||||
|
||||
NetworkPacket::NetworkPacket(const NetworkPacket& other) :
|
||||
_node(other._node),
|
||||
_nlPacket(other._nlPacket) {
|
||||
}
|
||||
|
||||
NetworkPacket::NetworkPacket(const SharedNodePointer& node, const NLPacket& packet) {
|
||||
if (packet.getSizeWithHeader() && packet.getSizeWithHeader() <= MAX_PACKET_SIZE) {
|
||||
_node = node;
|
||||
_nlPacket = packet;
|
||||
} else {
|
||||
qCDebug(networking, ">>> NetworkPacket::copyContents() unexpected length = %d", packet.size());
|
||||
}
|
||||
};
|
||||
|
||||
// copy assignment
|
||||
NetworkPacket& NetworkPacket::operator=(NetworkPacket const& other) {
|
||||
_node = other._node;
|
||||
_nlPacket = NLPacket::createCopy(other._nlPacket);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef HAS_MOVE_SEMANTICS
|
||||
// move, same as copy, but other packet won't be used further
|
||||
NetworkPacket::NetworkPacket(NetworkPacket&& other) :
|
||||
_node(std::move(other._node)),
|
||||
_nlPacket(std::move(other._nlPacket)) {
|
||||
}
|
||||
|
||||
// move assignment
|
||||
NetworkPacket& NetworkPacket::operator=(NetworkPacket&& other) {
|
||||
_node = std::move(other._node);
|
||||
_nlPacket = std::move(other._nlPacket);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
|
@ -1,42 +0,0 @@
|
|||
//
|
||||
// NetworkPacket.h
|
||||
// libraries/networking/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/9/13.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// A really simple class that stores a network packet between being received and being processed
|
||||
//
|
||||
// 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_NetworkPacket_h
|
||||
#define hifi_NetworkPacket_h
|
||||
|
||||
#include "NodeList.h"
|
||||
|
||||
/// Storage of not-yet processed inbound, or not yet sent outbound generic UDP network packet
|
||||
class NetworkPacket {
|
||||
public:
|
||||
NetworkPacket();
|
||||
NetworkPacket(const NetworkPacket& packet); // copy constructor
|
||||
NetworkPacket& operator= (const NetworkPacket& other); // copy assignment
|
||||
|
||||
#ifdef HAS_MOVE_SEMANTICS
|
||||
NetworkPacket(NetworkPacket&& other); // move?? // same as copy, but other packet won't be used further
|
||||
NetworkPacket& operator= (NetworkPacket&& other); // move assignment
|
||||
#endif
|
||||
|
||||
NetworkPacket(const SharedNodePointer& node, const NLPacket& nlPacket);
|
||||
|
||||
const SharedNodePointer& getNode() const { return _node; }
|
||||
const NLPacket& getPacket() const { return _nlPacket; }
|
||||
|
||||
private:
|
||||
|
||||
SharedNodePointer _node;
|
||||
NLPacket _nlPacket;
|
||||
};
|
||||
|
||||
#endif // hifi_NetworkPacket_h
|
|
@ -37,6 +37,8 @@ const quint64 DOMAIN_SERVER_CHECK_IN_MSECS = 1 * 1000;
|
|||
|
||||
const int MAX_SILENT_DOMAIN_SERVER_CHECK_INS = 5;
|
||||
|
||||
using std::pair<SharedNodePointer, std::unique_ptr<NLPacket>> NodePacketPair;
|
||||
|
||||
class Application;
|
||||
class Assignment;
|
||||
|
||||
|
|
|
@ -48,11 +48,13 @@ PacketSender::~PacketSender() {
|
|||
}
|
||||
|
||||
|
||||
void PacketSender::queuePacketForSending(const SharedNodePointer& destinationNode, const NLPacket& packet) {
|
||||
NetworkPacket networkPacket(destinationNode, packet);
|
||||
void PacketSender::queuePacketForSending(const SharedNodePointer& destinationNode, std::unique_ptr<NLPacket> packet) {
|
||||
NodePacketPair networkPacket(destinationNode, packet);
|
||||
|
||||
lock();
|
||||
_packets.push_back(networkPacket);
|
||||
unlock();
|
||||
|
||||
_totalPacketsQueued++;
|
||||
_totalBytesQueued += packet.getSizeWithHeader();
|
||||
|
||||
|
@ -264,20 +266,23 @@ bool PacketSender::nonThreadedProcess() {
|
|||
// Now that we know how many packets to send this call to process, just send them.
|
||||
while ((packetsSentThisCall < packetsToSendThisCall) && (packetsLeft > 0)) {
|
||||
lock();
|
||||
NetworkPacket& packet = _packets.front();
|
||||
NetworkPacket temporary = packet; // make a copy
|
||||
_packets.erase(_packets.begin());
|
||||
|
||||
NodePacketPair& packetPair = _packets.pop_front();
|
||||
packetsLeft = _packets.size();
|
||||
|
||||
unlock();
|
||||
|
||||
// send the packet through the NodeList...
|
||||
DependencyManager::get<NodeList>()->sendUnreliablePacket(temporary.getPacket(), temporary.getNode());
|
||||
DependencyManager::get<NodeList>()->sendUnreliablePacket(packetPair->second(), packetPair->first());
|
||||
|
||||
packetsSentThisCall++;
|
||||
_packetsOverCheckInterval++;
|
||||
_totalPacketsSent++;
|
||||
_totalBytesSent += temporary.getPacket().getSizeWithHeader();
|
||||
|
||||
emit packetSent(temporary.getPacket().getSizeWithHeader());
|
||||
int packetSize = packetPair->second().getSizeWithHeader();
|
||||
|
||||
_totalBytesSent += packetSize;
|
||||
emit packetSent(packetSize);
|
||||
|
||||
_lastSendTime = now;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <QWaitCondition>
|
||||
|
||||
#include "GenericThread.h"
|
||||
#include "NetworkPacket.h"
|
||||
#include "NodeList.h"
|
||||
#include "SharedUtil.h"
|
||||
|
||||
|
@ -39,7 +38,7 @@ public:
|
|||
~PacketSender();
|
||||
|
||||
/// Add packet to outbound queue.
|
||||
void queuePacketForSending(const SharedNodePointer& destinationNode, const NLPacket& packet);
|
||||
void queuePacketForSending(const SharedNodePointer& destinationNode, std::unique_ptr<NLPacket> packet);
|
||||
|
||||
void setPacketsPerSecond(int packetsPerSecond);
|
||||
int getPacketsPerSecond() const { return _packetsPerSecond; }
|
||||
|
@ -100,7 +99,7 @@ protected:
|
|||
SimpleMovingAverage _averageProcessCallTime;
|
||||
|
||||
private:
|
||||
std::vector<NetworkPacket> _packets;
|
||||
std::list<NodePacketPair> _packets;
|
||||
quint64 _lastSendTime;
|
||||
|
||||
bool threadedProcess();
|
||||
|
|
|
@ -21,7 +21,9 @@ void ReceivedPacketProcessor::queueReceivedPacket(const SharedNodePointer& sendi
|
|||
// Make sure our Node and NodeList knows we've heard from this node.
|
||||
sendingNode->setLastHeardMicrostamp(usecTimestampNow());
|
||||
|
||||
NetworkPacket networkPacket(sendingNode, packet);
|
||||
// TODO: fix the NodePacketPair once we've figured out receive API
|
||||
NodePacketPair networkPacket(sendingNode, NLPacket::create(PacketType::OctreeStats));
|
||||
|
||||
lock();
|
||||
_packets.push_back(networkPacket);
|
||||
_nodePacketCounts[sendingNode->getUUID()]++;
|
||||
|
@ -50,7 +52,8 @@ bool ReceivedPacketProcessor::process() {
|
|||
unlock();
|
||||
|
||||
foreach(auto& packet, currentPackets) {
|
||||
processPacket(packet.getNode(), packet.getByteArray());
|
||||
// TODO: Replace QByteArray() once NLPacket is coming through on receive side
|
||||
processPacket(packet->first(), QByteArray());
|
||||
midProcess();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include <QWaitCondition>
|
||||
|
||||
#include "GenericThread.h"
|
||||
#include "NetworkPacket.h"
|
||||
|
||||
/// Generalized threaded processor for handling received inbound packets.
|
||||
class ReceivedPacketProcessor : public GenericThread {
|
||||
|
@ -74,8 +73,7 @@ protected:
|
|||
virtual void postProcess() { }
|
||||
|
||||
protected:
|
||||
|
||||
QVector<NetworkPacket> _packets;
|
||||
std::list<NodePacketPair> _packets;
|
||||
QHash<QUuid, int> _nodePacketCounts;
|
||||
|
||||
QWaitCondition _hasPackets;
|
||||
|
|
Loading…
Reference in a new issue