mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 15:30:38 +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;
|
_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendQueue::sendPacket(const BasePacket& packet) {
|
void SendQueue::sendPacket(const Packet& packet) {
|
||||||
_socket->writeUnreliablePacket(packet, _destination);
|
if (_socket) {
|
||||||
|
_socket->writePacket(packet, _destination);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendQueue::ack(SequenceNumber ack) {
|
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
|
_naks.splice(_naks.end(), naks); // Add naks at the end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SequenceNumber SendQueue::getNextSequenceNumber() {
|
||||||
|
_atomicCurrentSequenceNumber = (SequenceNumber::Type)++_currentSequenceNumber;
|
||||||
|
return _currentSequenceNumber;
|
||||||
|
}
|
||||||
|
|
||||||
void SendQueue::sendNextPacket() {
|
void SendQueue::sendNextPacket() {
|
||||||
if (!_running) {
|
if (!_running) {
|
||||||
return;
|
return;
|
||||||
|
@ -131,9 +138,9 @@ void SendQueue::sendNextPacket() {
|
||||||
_lastSendTimestamp = sendTime;
|
_lastSendTimestamp = sendTime;
|
||||||
|
|
||||||
if (_nextPacket) {
|
if (_nextPacket) {
|
||||||
_nextPacket->setSequenceNumber(++_currentSequenceNumber);
|
// Write packet's sequence number and send it off
|
||||||
|
_nextPacket->setSequenceNumber(getNextSequenceNumber());
|
||||||
sendPacket(*_nextPacket);
|
sendPacket(*_nextPacket);
|
||||||
_atomicCurrentSequenceNumber.store((uint32_t) _currentSequenceNumber);
|
|
||||||
|
|
||||||
// Insert the packet we have just sent in the sent list
|
// Insert the packet we have just sent in the sent list
|
||||||
QWriteLocker locker(&_sentLock);
|
QWriteLocker locker(&_sentLock);
|
||||||
|
|
|
@ -50,7 +50,6 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
void sendPacket(const BasePacket& packet);
|
|
||||||
|
|
||||||
void ack(SequenceNumber ack);
|
void ack(SequenceNumber ack);
|
||||||
void nak(std::list<SequenceNumber> naks);
|
void nak(std::list<SequenceNumber> naks);
|
||||||
|
@ -66,15 +65,21 @@ private:
|
||||||
SendQueue(SendQueue&& other) = delete;
|
SendQueue(SendQueue&& other) = delete;
|
||||||
~SendQueue();
|
~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.
|
mutable QReadWriteLock _packetsLock; // Protects the packets to be sent list.
|
||||||
std::list<std::unique_ptr<Packet>> _packets; // List of packets to be sent
|
std::list<std::unique_ptr<Packet>> _packets; // List of packets to be sent
|
||||||
std::unique_ptr<Packet> _nextPacket; // Next packet to be sent
|
std::unique_ptr<Packet> _nextPacket; // Next packet to be sent
|
||||||
|
|
||||||
Socket* _socket { nullptr }; // Socket to send packet on
|
Socket* _socket { nullptr }; // Socket to send packet on
|
||||||
HifiSockAddr _destination; // Destination addr
|
HifiSockAddr _destination; // Destination addr
|
||||||
SequenceNumber _currentSequenceNumber; // Last sequence number sent out
|
|
||||||
SequenceNumber _lastAck; // Last ACKed sequence number
|
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::atomic<uint32_t> _atomicCurrentSequenceNumber; // Atomic for last sequence number sent out
|
||||||
|
|
||||||
std::unique_ptr<QTimer> _sendTimer; // Send timer
|
std::unique_ptr<QTimer> _sendTimer; // Send timer
|
||||||
|
|
Loading…
Reference in a new issue