--- mqtt/src/daemon.c 2012/04/25 13:33:53 1.2.2.13 +++ mqtt/src/daemon.c 2012/04/26 07:25:00 1.2.2.16 @@ -38,17 +38,9 @@ initSession(int sock, ait_val_t * __restrict v) else sess->sess_retry = strtol(str, NULL, 0); - if (!(sess->sess_root = schedBegin())) { - ioLIBERR(sched); - free(sess); - io_freeVar(v); - return NULL; - } - sess->sess_buf = mqtt_msgAlloc(USHRT_MAX); if (!sess->sess_buf) { ioLIBERR(mqtt); - schedEnd(&sess->sess_root); free(sess); io_freeVar(v); return NULL; @@ -59,7 +51,6 @@ initSession(int sock, ait_val_t * __restrict v) if (!sess->sess_srv) { ioDEBUG(3, "Error:: in srv_Init #%d - %s", mqtt_GetErrno(), mqtt_GetError()); mqtt_msgFree(&sess->sess_buf, 42); - schedEnd(&sess->sess_root); free(sess); io_freeVar(v); return NULL; @@ -107,8 +98,6 @@ finiSession(struct tagSession *sess) SESS_ELEM_UNLOCK(sess); pthread_mutex_destroy(&sess->sess_mtx); - schedEnd(&sess->sess_root); - if (sess->sess_will.msg) free(sess->sess_will.msg); if (sess->sess_will.topic) @@ -148,52 +137,6 @@ stopSession(struct tagSession *sess) sess->sess_addr, sess->sess_user); } -static int -KASession(struct tagSession *sess) -{ - mqtt_msg_t msg = { NULL, 0 }; - int ret; - struct pollfd pfd; - - ioTRACE(4); - - assert(sess); - - /* ping request */ - ret = mqtt_msgPINGREQ(&msg); - if ((ret = send(sess->sess_sock, msg.msg_base, ret, MSG_NOSIGNAL)) == -1) { - ioDEBUG(3, "Error:: send(%d) #%d - %s", sess->sess_sock, errno, strerror(errno)); - return -1; - } else { - ioDEBUG(5, "Sended %d bytes for ping request", ret); - free(msg.msg_base); - memset(&msg, 0, sizeof msg); - } - - pfd.fd = sess->sess_sock; - pfd.events = POLLIN | POLLPRI; - if ((ret = poll(&pfd, 1, sess->sess_ka * 1000)) == -1 || - pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { - ioDEBUG(3, "Error:: poll(%d) #%d - %s", sess->sess_sock, errno, strerror(errno)); - return -1; - } else if (!ret) { - ioDEBUG(5, "Warning:: Session is abandoned ... must be disconnect!"); - return 1; - } - /* receive & decode packet */ - if (recv(sess->sess_sock, sess->sess_buf->msg_base, sess->sess_buf->msg_len, 0) == -1) { - ioDEBUG(3, "Error:: recv(%d) #%d - %s", sess->sess_sock, errno, strerror(errno)); - return -1; - } - if (mqtt_readPINGRESP(sess->sess_buf)) { - ioDEBUG(5, "Warning:: Session is broken, not hear ping response ... must be disconnect!"); - return 2; - } - - /* Keep Alive is OK! */ - return 0; -} - static void * thrSession(struct tagSession *sess) { @@ -212,7 +155,7 @@ thrSession(struct tagSession *sess) pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { ioDEBUG(3, "Error:: poll(%d) #%d - %s", sess->sess_sock, errno, strerror(errno)); break; - } else if (!ret && (ret = KASession(sess))) { + } else if (!ret && (ret = mqtt_KeepAlive(sess->sess_sock, sess->sess_ka, 1))) { call.LOG(logg, "Session %s keep-alive missing from %s for user %s ...\n", sess->sess_cid, sess->sess_addr, sess->sess_user); break; @@ -247,13 +190,14 @@ thrSession(struct tagSession *sess) locKill ^= locKill; break; case MQTT_TYPE_DISCONNECT: + /* ioDEBUG(5, "Exec DISCONNECT session"); - finiSession(sess); - SESS_LOCK; TAILQ_REMOVE(&Sessions, sess, sess_node); SESS_UNLOCK; + */ + finiSession(sess); locKill ^= locKill; continue; case MQTT_TYPE_PUBLISH: