Commit 1907e5f5c8b173c66a9504b6cd88359bbc861427
1 parent
1ee96e98
Don't save sessions from 'clean session' clients
Showing
3 changed files
with
17 additions
and
0 deletions
session.cpp
| ... | ... | @@ -282,3 +282,13 @@ void Session::removeOutgoingQoS2MessageId(u_int16_t packet_id) |
| 282 | 282 | if (it != outgoingQoS2MessageIds.end()) |
| 283 | 283 | outgoingQoS2MessageIds.erase(it); |
| 284 | 284 | } |
| 285 | + | |
| 286 | +bool Session::getCleanSession() const | |
| 287 | +{ | |
| 288 | + auto c = client.lock(); | |
| 289 | + | |
| 290 | + if (!c) | |
| 291 | + return false; | |
| 292 | + | |
| 293 | + return c->getCleanSession(); | |
| 294 | +} | ... | ... |
session.h
subscriptionstore.cpp
| ... | ... | @@ -685,6 +685,11 @@ void SubscriptionStore::saveSessionsAndSubscriptions(const std::string &filePath |
| 685 | 685 | for (const auto &pair : sessionsByIdConst) |
| 686 | 686 | { |
| 687 | 687 | const Session &org = *pair.second.get(); |
| 688 | + | |
| 689 | + // Sessions created with clean session need to be destroyed when disconnecting, so no point in saving them. | |
| 690 | + if (org.getCleanSession()) | |
| 691 | + continue; | |
| 692 | + | |
| 688 | 693 | sessionCopies.push_back(org.getCopy()); |
| 689 | 694 | } |
| 690 | 695 | ... | ... |