mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Added SendQueue::getNextSeqNum
This commit is contained in:
parent
8a474ac20a
commit
f53637f19e
2 changed files with 18 additions and 6 deletions
|
@ -80,8 +80,10 @@ void SendQueue::stop() {
|
|||
_running = false;
|
||||
}
|
||||
|
||||
void SendQueue::sendPacket(const BasePacket& packet) {
|
||||
_socket->writeUnreliablePacket(packet, _destination);
|
||||
void SendQueue::sendPacket(const Packet& packet) {
|
||||
if (_socket) {
|
||||
_socket->writePacket(packet, _destination);
|
||||
}
|
||||
}
|
||||
|
||||
void SendQueue::ack(SequenceNumber ack) {
|
||||
|
@ -121,6 +123,11 @@ void SendQueue::nak(std::list<SequenceNumber> naks) {
|
|||
_naks.splice(_naks.end(), naks); // Add naks at the end
|
||||
}
|
||||
|
||||
SequenceNumber SendQueue::getNextSequenceNumber() {
|
||||
_atomicCurrentSequenceNumber = (SequenceNumber::Type)++_currentSequenceNumber;
|
||||
return _currentSequenceNumber;
|
||||
}
|
||||
|
||||
void SendQueue::sendNextPacket() {
|
||||
if (!_running) {
|
||||
return;
|
||||
|
@ -131,9 +138,9 @@ void SendQueue::sendNextPacket() {
|
|||
_lastSendTimestamp = sendTime;
|
||||
|
||||
if (_nextPacket) {
|
||||
_nextPacket->setSequenceNumber(++_currentSequenceNumber);
|
||||
// Write packet's sequence number and send it off
|
||||
_nextPacket->setSequenceNumber(getNextSequenceNumber());
|
||||
sendPacket(*_nextPacket);
|
||||
_atomicCurrentSequenceNumber.store((uint32_t) _currentSequenceNumber);
|
||||
|
||||
// Insert the packet we have just sent in the sent list
|
||||
QWriteLocker locker(&_sentLock);
|
||||
|
|
|
@ -50,7 +50,6 @@ public:
|
|||
public slots:
|
||||
void start();
|
||||
void stop();
|
||||
void sendPacket(const BasePacket& packet);
|
||||
|
||||
void ack(SequenceNumber ack);
|
||||
void nak(std::list<SequenceNumber> naks);
|
||||
|
@ -66,15 +65,21 @@ private:
|
|||
SendQueue(SendQueue&& other) = delete;
|
||||
~SendQueue();
|
||||
|
||||
// Increments current sequence number and return it
|
||||
SequenceNumber getNextSequenceNumber();
|
||||
|
||||
// Send a packet through the socket
|
||||
void sendPacket(const Packet& packet);
|
||||
|
||||
mutable QReadWriteLock _packetsLock; // Protects the packets to be sent list.
|
||||
std::list<std::unique_ptr<Packet>> _packets; // List of packets to be sent
|
||||
std::unique_ptr<Packet> _nextPacket; // Next packet to be sent
|
||||
|
||||
Socket* _socket { nullptr }; // Socket to send packet on
|
||||
HifiSockAddr _destination; // Destination addr
|
||||
SequenceNumber _currentSequenceNumber; // Last sequence number sent out
|
||||
SequenceNumber _lastAck; // Last ACKed sequence number
|
||||
|
||||
SequenceNumber _currentSequenceNumber; // Last sequence number sent out
|
||||
std::atomic<uint32_t> _atomicCurrentSequenceNumber; // Atomic for last sequence number sent out
|
||||
|
||||
std::unique_ptr<QTimer> _sendTimer; // Send timer
|
||||
|
|
Loading…
Reference in a new issue