mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 12:15:30 +02:00
Added takeFront method to PacketList
This commit is contained in:
parent
bbb00b9d3a
commit
c05105e2f9
2 changed files with 15 additions and 4 deletions
|
@ -288,10 +288,8 @@ qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& des
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr) {
|
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr) {
|
||||||
qint64 bytesSent{ 0 };
|
qint64 bytesSent{ 0 };
|
||||||
auto& packets = packetList._packets;
|
while (!packetList._packets.empty()) {
|
||||||
while (!packets.empty()) {
|
bytesSent += sendPacket(std::move(packetList.takeFront<NLPacket>()), sockAddr);
|
||||||
bytesSent += sendPacket(std::move(packets.front()), sockAddr);
|
|
||||||
packets.pop_front();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesSent;
|
return bytesSent;
|
||||||
|
|
|
@ -47,6 +47,10 @@ private:
|
||||||
PacketList(const PacketList& other) = delete;
|
PacketList(const PacketList& other) = delete;
|
||||||
PacketList& operator=(const PacketList& other) = delete;
|
PacketList& operator=(const PacketList& other) = delete;
|
||||||
|
|
||||||
|
// Takes the first packet of the list and returns it.
|
||||||
|
template<typename T> std::unique_ptr<T> takeFront();
|
||||||
|
|
||||||
|
// Creates a new packet, can be overriden to change return underlying type
|
||||||
virtual std::unique_ptr<Packet> createPacket();
|
virtual std::unique_ptr<Packet> createPacket();
|
||||||
std::unique_ptr<Packet> createPacketWithExtendedHeader();
|
std::unique_ptr<Packet> createPacketWithExtendedHeader();
|
||||||
|
|
||||||
|
@ -62,6 +66,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> qint64 PacketList::readPrimitive(T* data) {
|
template <typename T> qint64 PacketList::readPrimitive(T* data) {
|
||||||
|
static_assert(!std::is_pointer<T>::value, "T must not be a pointer");
|
||||||
return QIODevice::read(reinterpret_cast<char*>(data), sizeof(T));
|
return QIODevice::read(reinterpret_cast<char*>(data), sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,4 +75,12 @@ template <typename T> qint64 PacketList::writePrimitive(const T& data) {
|
||||||
return QIODevice::write(reinterpret_cast<const char*>(&data), sizeof(T));
|
return QIODevice::write(reinterpret_cast<const char*>(&data), sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T> std::unique_ptr<T> PacketList::takeFront() {
|
||||||
|
static_assert(std::is_base_of<Packet, T>::value, "T must derive from Packet.");
|
||||||
|
|
||||||
|
auto packet = std::move(_packets.front());
|
||||||
|
_packets.pop_front();
|
||||||
|
return std::move(std::unique_ptr<T>(dynamic_cast<T*>(packet.release())));
|
||||||
|
}
|
||||||
|
|
||||||
#endif // hifi_PacketList_h
|
#endif // hifi_PacketList_h
|
Loading…
Reference in a new issue