14 #ifndef hifi_PacketSender_h
15 #define hifi_PacketSender_h
17 #include <QWaitCondition>
19 #include "GenericThread.h"
21 #include "SharedUtil.h"
28 static const quint64 USECS_PER_SECOND;
29 static const quint64 SENDING_INTERVAL_ADJUST;
30 static const int TARGET_FPS;
31 static const int MAX_SLEEP_INTERVAL;
33 static const int DEFAULT_PACKETS_PER_SECOND;
34 static const int MINIMUM_PACKETS_PER_SECOND;
35 static const int MINIMAL_SLEEP_INTERVAL;
37 PacketSender(
int packetsPerSecond = DEFAULT_PACKETS_PER_SECOND);
41 void queuePacketForSending(
const SharedNodePointer& destinationNode, std::unique_ptr<NLPacket> packet);
42 void queuePacketListForSending(
const SharedNodePointer& destinationNode, std::unique_ptr<NLPacketList> packetList);
44 void setPacketsPerSecond(
int packetsPerSecond);
45 int getPacketsPerSecond()
const {
return _packetsPerSecond; }
47 virtual bool process()
override;
48 virtual void terminating()
override;
95 void packetSent(quint64);
97 int _packetsPerSecond;
98 int _usecsPerProcessCallHint;
99 quint64 _lastProcessCallTime;
100 SimpleMovingAverage _averageProcessCallTime;
103 std::list<NodePacketOrPacketListPair> _packets;
104 quint64 _lastSendTime;
106 bool threadedProcess();
107 bool nonThreadedProcess();
109 quint64 _lastPPSCheck;
110 size_t _packetsOverCheckInterval;
113 quint64 _totalPacketsSent;
114 quint64 _totalBytesSent;
116 quint64 _totalPacketsQueued;
117 quint64 _totalBytesQueued;
119 QWaitCondition _hasPackets;
120 QMutex _waitingOnPacketsMutex;
Definition: GenericThread.h:23
Generalized threaded processor for queueing and sending of outbound packets.
Definition: PacketSender.h:24
quint64 getLifetimeBytesQueued() const
returns the total bytes queued by this object over its lifetime
Definition: PacketSender.h:93
quint64 getLifetimeInUsecs() const
returns lifetime of this object from first packet sent to now in usecs
Definition: PacketSender.h:78
quint64 getLifetimeBytesSent() const
returns the total bytes sent by this object over its lifetime
Definition: PacketSender.h:87
float getLifetimePPS() const
returns the packets per second send rate of this object over its lifetime
Definition: PacketSender.h:62
quint64 getLifetimePacketsSent() const
returns the total packets sent by this object over its lifetime
Definition: PacketSender.h:84
float getLifetimePPSQueued() const
returns the packets per second queued rate of this object over its lifetime
Definition: PacketSender.h:70
bool hasPacketsToSend() const
are there packets waiting in the send queue to be sent
Definition: PacketSender.h:51
quint64 getLifetimePacketsQueued() const
returns the total packets queued by this object over its lifetime
Definition: PacketSender.h:90
virtual bool process() override
Override this function to do whatever your class actually does, return false to exit thread early.
Definition: PacketSender.cpp:81
void queuePacketForSending(const SharedNodePointer &destinationNode, std::unique_ptr< NLPacket > packet)
Add packet to outbound queue.
Definition: PacketSender.cpp:52
float getLifetimeBPS() const
returns the bytes per second send rate of this object over its lifetime
Definition: PacketSender.h:66
void setProcessCallIntervalHint(int usecsPerProcessCall)
Definition: PacketSender.h:59
size_t packetsToSendCount() const
how many packets are there in the send queue waiting to be sent
Definition: PacketSender.h:54
float getLifetimeInSeconds() const
returns lifetime of this object from first packet sent to now in usecs
Definition: PacketSender.h:81
float getLifetimeBPSQueued() const
returns the bytes per second queued rate of this object over its lifetime
Definition: PacketSender.h:74