51 lines
1.3 KiB
C
51 lines
1.3 KiB
C
|
#pragma once
|
||
|
|
||
|
#include <memory>
|
||
|
#include <protocol/Packet.h>
|
||
|
|
||
|
#define DEBUG_ACKNOWLEDGE
|
||
|
namespace ts {
|
||
|
namespace connection {
|
||
|
class VoiceClientConnection;
|
||
|
class AcknowledgeManager {
|
||
|
struct Entry {
|
||
|
uint16_t packet_id = 0;
|
||
|
uint8_t packet_type = 0xFF;
|
||
|
uint8_t resend_count = 0;
|
||
|
bool acknowledged : 1;
|
||
|
uint8_t send_count : 7;
|
||
|
|
||
|
|
||
|
pipes::buffer buffer;
|
||
|
std::chrono::system_clock::time_point first_send;
|
||
|
std::chrono::system_clock::time_point next_resend;
|
||
|
std::chrono::milliseconds resend_period;
|
||
|
|
||
|
std::unique_ptr<threads::Future<bool>> acknowledge_listener;
|
||
|
};
|
||
|
public:
|
||
|
AcknowledgeManager();
|
||
|
virtual ~AcknowledgeManager();
|
||
|
|
||
|
size_t awaiting_acknowledge();
|
||
|
void reset();
|
||
|
|
||
|
void process_packet(ts::protocol::BasicPacket& /* packet */);
|
||
|
bool process_acknowledge(const ts::protocol::BasicPacket& /* packet */, std::string& /* error */);
|
||
|
|
||
|
ssize_t execute_resend(
|
||
|
const std::chrono::system_clock::time_point& /* now */,
|
||
|
std::chrono::system_clock::time_point& /* next resend */,
|
||
|
std::deque<pipes::buffer>& /* buffers to resend */,
|
||
|
std::string& /* error */
|
||
|
);
|
||
|
private:
|
||
|
std::recursive_mutex entry_lock;
|
||
|
std::deque<std::shared_ptr<Entry>> entries;
|
||
|
|
||
|
std::chrono::milliseconds resend_delay{500};
|
||
|
|
||
|
double average_response = 20;
|
||
|
};
|
||
|
}
|
||
|
}
|