* MDF [clean_session] restructure cahcing method
@@ -600,31 +600,6 @@ nano_session_cache(nano_pipe *p)
nni_id_map *nano_qos_db = cp->nano_qos_db;
client_ctx *cli_ctx = NULL;
struct topic_queue * tq = NULL;
-
- if (cp->clean_start == 1) {
- // step 0 conn_param will be deleted anyway, so won't bother to
- // do anything step 1 delete nano_qos_db
- nni_id_iterate(nano_qos_db, nni_id_msgfree_cb);
- nni_id_map_fini(nano_qos_db);
- nng_free(nano_qos_db, sizeof(struct nni_id_map));
- // step 2-1 delete topics from tree, delete cli_ctx
- // step 2-2 delete topics from hash.cc
- if (check_id(p->id) && p->tree != NULL) {
- tq = get_topic(p->id);
- if ((cli_ctx = del_topic_clictx_from_tree(p->tree, tq, p->id)) != NULL) {
- debug_msg("(CS=1) Unexpected, not all topic has been delete from sub_pkt");
- }
- del_topic_all(p->id);
- } else {
- debug_msg("(CS=1) UNEXPECTED: no stored topic queue, tq lost or maybe not subed any topic");
- }
- // step 3 delete topics from nano_pipe_db
- nano_msg_free_pipedb(p->pipedb_root);
-
- debug_msg("(CS=1) Session not cached, all this session related information disgarded");
- return 0;
- }
-
nano_sock * s = p->rep;
uint32_t key = DJBHashn(cp->clientid.body, cp->clientid.len);
nni_id_map *cs_db = &s->clean_session_db;
@@ -692,7 +667,33 @@ nano_pipe_fini(void *arg)
// MQTT_DB
debug_msg("deleting %d", p->id);
+
+ if (p->conn_param->clean_start == 1) {
+ // When clean_session is set to 1
+ nni_id_map * nano_qos_db = p->conn_param->nano_qos_db;
+ client_ctx * cli_ctx = NULL;
+ struct topic_queue *tq = NULL;
+
+ nni_id_iterate(nano_qos_db, nni_id_msgfree_cb);
+ nni_id_map_fini(nano_qos_db);
+ nng_free(nano_qos_db, sizeof(struct nni_id_map));
+
+ if (check_id(p->id) && p->tree != NULL) {
+ tq = get_topic(p->id);
+ if ((cli_ctx = del_topic_clictx_from_tree(
+ p->tree, tq, p->id)) != NULL) {
+ debug_msg("(CS=1) Unexpected, not all topic "
+ "has been delete from sub_pkt");
+ }
+ del_topic_all(p->id);
+ } else {
+ debug_msg("(CS=1) UNEXPECTED: no stored topic queue, "
+ "tq lost or maybe not subed any topic");
+ }
+ nano_msg_free_pipedb(p->pipedb_root);
+ } else
nano_session_cache(p);
+
destroy_conn_param(p->conn_param);
nni_mtx_fini(&p->lk);
