--- mqtt/src/mqttd_calls.c 2012/01/30 13:39:22 1.2.2.2 +++ mqtt/src/mqttd_calls.c 2012/04/11 16:37:17 1.2.2.3 @@ -112,31 +112,33 @@ cmdCONNECT(void *srv, void *arg) { struct tagStore *store; struct tagSession *sess = (struct tagSession*) arg; + register int i; ioTRACE(2); if (!sess) return -1; - pthread_mutex_lock(&mtx_sess); + SESS_LOCK; TAILQ_REMOVE(&Sessions, sess, sess_node); - pthread_mutex_unlock(&mtx_sess); + SESS_UNLOCK; if (call.FiniSessPUB) call.FiniSessPUB(&cfg, pub, sess->sess_cid, sess->sess_user, "%"); - pthread_mutex_lock(&sess->sess_mtx); - while ((store = TAILQ_FIRST(&sess->sess_sndqueue))) { - TAILQ_REMOVE(&sess->sess_sndqueue, store, st_node); + SESS_ELEM_LOCK(sess); + for (i = 0; i < MQTT_QOS_RESERVED; i++) + while ((store = SLIST_FIRST(&sess->sess_txque[i]))) { + SLIST_REMOVE_HEAD(&sess->sess_txque[i], st_node); - if (store->st_subscr.sub_topic.msg_base) - free(store->st_subscr.sub_topic.msg_base); - if (store->st_subscr.sub_value.msg_base) - free(store->st_subscr.sub_value.msg_base); + if (store->st_subscr.sub_topic.msg_base) + free(store->st_subscr.sub_topic.msg_base); + if (store->st_subscr.sub_value.msg_base) + free(store->st_subscr.sub_value.msg_base); - free(store); - } - pthread_mutex_unlock(&sess->sess_mtx); + free(store); + } + SESS_ELEM_UNLOCK(sess); if (sess->sess_will.msg) free(sess->sess_will.msg); @@ -158,9 +160,9 @@ cmdDISCONNECT(void *srv, void *arg) if (!sess) return -1; - pthread_mutex_lock(&mtx_sess); + SESS_LOCK; TAILQ_REMOVE(&Sessions, sess, sess_node); - pthread_mutex_unlock(&mtx_sess); + SESS_UNLOCK; call.LOG(logg, "Session %s stopped from %s for user %s.\n", sess->sess_cid, sess->sess_addr, sess->sess_user);