Clear expired streams

This commit is contained in:
nsubiron 2019-01-18 16:53:37 +01:00
parent bd398acf28
commit e231d71f18
2 changed files with 11 additions and 0 deletions

View File

@ -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;
}
} }
} }

View File

@ -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;