|
|
@@ -11,7 +11,7 @@ PacketQueue::PacketQueue(int max_entries) {
|
|
|
int PacketQueue::countBefore(uint32_t now) const {
|
|
|
int n = 0;
|
|
|
for (int j = 0; j < _num; j++) {
|
|
|
- if (_schedule_table[j] > now) continue; // scheduled for future... ignore for now
|
|
|
+ if ((int32_t)(_schedule_table[j] - now) > 0) continue; // scheduled for future... ignore for now
|
|
|
n++;
|
|
|
}
|
|
|
return n;
|
|
|
@@ -21,7 +21,7 @@ mesh::Packet* PacketQueue::get(uint32_t now) {
|
|
|
uint8_t min_pri = 0xFF;
|
|
|
int best_idx = -1;
|
|
|
for (int j = 0; j < _num; j++) {
|
|
|
- if (_schedule_table[j] > now) continue; // scheduled for future... ignore for now
|
|
|
+ if ((int32_t)(_schedule_table[j] - now) > 0) continue; // scheduled for future... ignore for now
|
|
|
if (_pri_table[j] < min_pri) { // select most important priority amongst non-future entries
|
|
|
min_pri = _pri_table[j];
|
|
|
best_idx = j;
|
|
|
@@ -55,15 +55,15 @@ mesh::Packet* PacketQueue::removeByIdx(int i) {
|
|
|
return item;
|
|
|
}
|
|
|
|
|
|
-void PacketQueue::add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
|
|
+bool PacketQueue::add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
|
|
if (_num == _size) {
|
|
|
- // TODO: log "FATAL: queue is full!"
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
_table[_num] = packet;
|
|
|
_pri_table[_num] = priority;
|
|
|
_schedule_table[_num] = scheduled_for;
|
|
|
_num++;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
StaticPoolPacketManager::StaticPoolPacketManager(int pool_size): unused(pool_size), send_queue(pool_size), rx_queue(pool_size) {
|
|
|
@@ -82,7 +82,10 @@ void StaticPoolPacketManager::free(mesh::Packet* packet) {
|
|
|
}
|
|
|
|
|
|
void StaticPoolPacketManager::queueOutbound(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
|
|
- send_queue.add(packet, priority, scheduled_for);
|
|
|
+ if (!send_queue.add(packet, priority, scheduled_for)) {
|
|
|
+ MESH_DEBUG_PRINTLN("queueOutbound: send queue full, dropping packet");
|
|
|
+ free(packet);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
mesh::Packet* StaticPoolPacketManager::getNextOutbound(uint32_t now) {
|
|
|
@@ -106,7 +109,10 @@ mesh::Packet* StaticPoolPacketManager::removeOutboundByIdx(int i) {
|
|
|
}
|
|
|
|
|
|
void StaticPoolPacketManager::queueInbound(mesh::Packet* packet, uint32_t scheduled_for) {
|
|
|
- rx_queue.add(packet, 0, scheduled_for);
|
|
|
+ if (!rx_queue.add(packet, 0, scheduled_for)) {
|
|
|
+ MESH_DEBUG_PRINTLN("queueInbound: rx queue full, dropping packet");
|
|
|
+ free(packet);
|
|
|
+ }
|
|
|
}
|
|
|
mesh::Packet* StaticPoolPacketManager::getNextInbound(uint32_t now) {
|
|
|
return rx_queue.get(now);
|