More impl, fix move for TSQueue
This commit is contained in:
parent
1e0f631ab2
commit
0065928422
3 changed files with 68 additions and 7 deletions
|
@ -18,9 +18,9 @@ class TSQueue {
|
||||||
// disable copy
|
// disable copy
|
||||||
TSQueue(const TSQueue &other) = delete;
|
TSQueue(const TSQueue &other) = delete;
|
||||||
TSQueue &operator=(const TSQueue &other) = delete;
|
TSQueue &operator=(const TSQueue &other) = delete;
|
||||||
// disable move
|
// enable move
|
||||||
TSQueue(TSQueue &&other) = delete;
|
TSQueue(TSQueue &&other);
|
||||||
TSQueue &operator=(TSQueue &&other) = delete;
|
TSQueue &operator=(TSQueue &&other);
|
||||||
|
|
||||||
bool push(const T &data);
|
bool push(const T &data);
|
||||||
T top();
|
T top();
|
||||||
|
@ -43,6 +43,27 @@ rb(capacity)
|
||||||
rb.setResizePolicy(false);
|
rb.setResizePolicy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
TSQueue<T>::TSQueue(TSQueue &&other) :
|
||||||
|
TSQueue<T>::TSQueue(other.rb.getCapacity())
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(other.mutex);
|
||||||
|
for(unsigned int i = 0; i < other.rb.getSize(); ++i) {
|
||||||
|
rb.push(other.rb[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
TSQueue<T>& TSQueue<T>::operator =(TSQueue &&other)
|
||||||
|
{
|
||||||
|
std::scoped_lock lock(other.mutex, mutex);
|
||||||
|
rb.resize(0);
|
||||||
|
rb.changeCapacity(other.rb.getCapacity());
|
||||||
|
for(unsigned int i = 0; i < other.rb.getSize(); ++i) {
|
||||||
|
rb.push(other.rb[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
TSQueue<T>::~TSQueue()
|
TSQueue<T>::~TSQueue()
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -37,6 +37,14 @@ struct ConnectionData {
|
||||||
ConnectionData();
|
ConnectionData();
|
||||||
ConnectionData(bool isServer, Context *ctx);
|
ConnectionData(bool isServer, Context *ctx);
|
||||||
|
|
||||||
|
// copy
|
||||||
|
ConnectionData(const ConnectionData& other) = delete;
|
||||||
|
ConnectionData& operator=(const ConnectionData& other) = delete;
|
||||||
|
|
||||||
|
// move
|
||||||
|
ConnectionData(ConnectionData&& other) = default;
|
||||||
|
ConnectionData& operator=(ConnectionData&& other) = default;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 0 - trigger send
|
* 0 - trigger send
|
||||||
* 1 - is good mode
|
* 1 - is good mode
|
||||||
|
@ -54,7 +62,7 @@ struct ConnectionData {
|
||||||
float toggleTimer;
|
float toggleTimer;
|
||||||
float toggledTimer;
|
float toggledTimer;
|
||||||
uint32_t addr; // in network order
|
uint32_t addr; // in network order
|
||||||
uint16_t port;
|
uint16_t port; // in native order
|
||||||
std::deque<UDPC_PacketInfo> sentPkts;
|
std::deque<UDPC_PacketInfo> sentPkts;
|
||||||
TSQueue<UDPC_PacketInfo> sendPkts;
|
TSQueue<UDPC_PacketInfo> sendPkts;
|
||||||
TSQueue<UDPC_PacketInfo> priorityPkts;
|
TSQueue<UDPC_PacketInfo> priorityPkts;
|
||||||
|
|
|
@ -9,11 +9,16 @@
|
||||||
|
|
||||||
UDPC::ConnectionData::ConnectionData() :
|
UDPC::ConnectionData::ConnectionData() :
|
||||||
flags(),
|
flags(),
|
||||||
|
timer(0.0f),
|
||||||
|
toggleT(30.0f),
|
||||||
|
toggleTimer(0.0f),
|
||||||
|
toggledTimer(0.0f),
|
||||||
sentPkts(),
|
sentPkts(),
|
||||||
sendPkts(UDPC_QUEUED_PKTS_MAX_SIZE),
|
sendPkts(UDPC_QUEUED_PKTS_MAX_SIZE),
|
||||||
priorityPkts(UDPC_QUEUED_PKTS_MAX_SIZE),
|
priorityPkts(UDPC_QUEUED_PKTS_MAX_SIZE),
|
||||||
received(std::chrono::steady_clock::now()),
|
received(std::chrono::steady_clock::now()),
|
||||||
sent(std::chrono::steady_clock::now())
|
sent(std::chrono::steady_clock::now()),
|
||||||
|
rtt(0.0f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,10 +509,37 @@ void UDPC_update(void *ctx) {
|
||||||
// is receiving as server, connection did not already exist
|
// is receiving as server, connection did not already exist
|
||||||
// TODO log establishing connection with client peer
|
// TODO log establishing connection with client peer
|
||||||
UDPC::ConnectionData newConnection(true, c);
|
UDPC::ConnectionData newConnection(true, c);
|
||||||
// TODO update idMap and conMap with new CD
|
newConnection.addr = receivedData.sin_addr.s_addr;
|
||||||
// TODO impl establish connection with client peer as server
|
newConnection.port = ntohs(receivedData.sin_port);
|
||||||
|
|
||||||
|
c->idMap.insert(std::make_pair(newConnection.id, newConnection.addr));
|
||||||
|
c->conMap.insert(std::make_pair(newConnection.addr, std::move(newConnection)));
|
||||||
|
// TODO trigger event server established connection with client
|
||||||
|
} else if (c->flags.test(1)) {
|
||||||
|
// is client
|
||||||
|
auto iter = c->conMap.find(receivedData.sin_addr.s_addr);
|
||||||
|
if(iter == c->conMap.end() || !iter->second.flags.test(3)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
iter->second.flags.reset(3);
|
||||||
|
iter->second.id = conID;
|
||||||
|
iter->second.flags.set(4);
|
||||||
|
// TODO trigger event client established connection with server
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto iter = c->conMap.find(receivedData.sin_addr.s_addr);
|
||||||
|
if(iter == c->conMap.end() || iter->second.flags.test(3)
|
||||||
|
|| !iter->second.flags.test(4) || iter->second.id != conID) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if(isPing) {
|
||||||
|
iter->second.flags.set(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// packet is valid
|
||||||
|
// TODO log received valid packet
|
||||||
|
|
||||||
// TODO impl
|
// TODO impl
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue