mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[ntcore] Various fixes and cleanups (#4544)
* NetworkTableInstance: set handle to 0 after destroy * Fix multiple notifications of local values * Detect mismatch between handles * Server: fix setting min period when no topics * Limit maximum number of subscribers/publishers/listeners This helps find resource leaks and prevents them from causing excessive slowdowns/crashes. The limit on each is currently set to 512. * Don't use std::swap in move operation
This commit is contained in:
@@ -620,8 +620,20 @@ void ClientData4Base::ClientSubscribe(int64_t subuid,
|
||||
sub->periodMs = kMinPeriodMs;
|
||||
}
|
||||
|
||||
// update periodic sender (if not local)
|
||||
if (!m_local) {
|
||||
if (m_periodMs == UINT32_MAX) {
|
||||
m_periodMs = sub->periodMs;
|
||||
} else {
|
||||
m_periodMs = std::gcd(m_periodMs, sub->periodMs);
|
||||
}
|
||||
if (m_periodMs < kMinPeriodMs) {
|
||||
m_periodMs = kMinPeriodMs;
|
||||
}
|
||||
m_setPeriodic(m_periodMs);
|
||||
}
|
||||
|
||||
// see if this immediately subscribes to any topics
|
||||
bool updatedPeriodic = false;
|
||||
for (auto&& topic : m_server.m_topics) {
|
||||
bool removed = false;
|
||||
if (replace) {
|
||||
@@ -647,14 +659,6 @@ void ClientData4Base::ClientSubscribe(int64_t subuid,
|
||||
m_server.UpdateMetaTopicSub(topic.get());
|
||||
}
|
||||
|
||||
if (added || removed) {
|
||||
// update periodic sender (if not local)
|
||||
if (!m_local) {
|
||||
m_periodMs = std::gcd(m_periodMs, sub->periodMs);
|
||||
updatedPeriodic = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wasSubscribed && added && !removed) {
|
||||
// announce topic to client
|
||||
DEBUG4("client {}: announce {}", m_id, topic->name);
|
||||
@@ -667,12 +671,6 @@ void ClientData4Base::ClientSubscribe(int64_t subuid,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (updatedPeriodic) {
|
||||
if (m_periodMs < kMinPeriodMs) {
|
||||
m_periodMs = kMinPeriodMs;
|
||||
}
|
||||
m_setPeriodic(m_periodMs);
|
||||
}
|
||||
|
||||
// update meta data
|
||||
UpdateMetaClientSub();
|
||||
|
||||
Reference in New Issue
Block a user