Clear expired streams
This commit is contained in:
parent
bd398acf28
commit
e231d71f18
|
@ -72,6 +72,7 @@ namespace detail {
|
||||||
void Dispatcher::DeregisterSession(std::shared_ptr<Session> session) {
|
void Dispatcher::DeregisterSession(std::shared_ptr<Session> session) {
|
||||||
DEBUG_ASSERT(session != nullptr);
|
DEBUG_ASSERT(session != nullptr);
|
||||||
std::lock_guard<std::mutex> lock(_mutex);
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
|
ClearExpiredStreams();
|
||||||
auto search = _stream_map.find(session->get_stream_id());
|
auto search = _stream_map.find(session->get_stream_id());
|
||||||
if (search != _stream_map.end()) {
|
if (search != _stream_map.end()) {
|
||||||
auto stream_state = search->second.lock();
|
auto stream_state = search->second.lock();
|
||||||
|
@ -80,6 +81,14 @@ namespace detail {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Dispatcher::ClearExpiredStreams() {
|
||||||
|
for (auto it = _stream_map.begin(); it != _stream_map.end(); ) {
|
||||||
|
if (it->second.expired()) {
|
||||||
|
it = _stream_map.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ namespace detail {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void ClearExpiredStreams();
|
||||||
|
|
||||||
// We use a mutex here, but we assume that sessions and streams won't be
|
// We use a mutex here, but we assume that sessions and streams won't be
|
||||||
// created too often.
|
// created too often.
|
||||||
std::mutex _mutex;
|
std::mutex _mutex;
|
||||||
|
|
Loading…
Reference in New Issue