version 1.2.2.17, 2012/05/22 14:15:04
|
version 1.2.2.21, 2012/06/01 13:13:40
|
Line 4
|
Line 4
|
#include "mqttd_calls.h" |
#include "mqttd_calls.h" |
|
|
|
|
|
static inline struct tagPkt * |
|
mkPkt(void * __restrict data, int dlen) |
|
{ |
|
struct tagPkt *p = NULL; |
|
|
|
p = io_malloc(sizeof(struct tagPkt)); |
|
if (!p) { |
|
ioDEBUG(7, "Error:: in send packet prepare #%d - %s", io_GetErrno(), io_GetError()); |
|
return NULL; |
|
} else |
|
memset(p, 0, sizeof(struct tagPkt)); |
|
|
|
p->pkt_data = io_allocVar(); |
|
if (!p->pkt_data) { |
|
ioDEBUG(7, "Error:: in send packet prepare #%d - %s", io_GetErrno(), io_GetError()); |
|
io_free(p); |
|
return NULL; |
|
} |
|
|
|
if (data && dlen > 0) |
|
AIT_SET_BUF(p->pkt_data, data, dlen); |
|
|
|
return p; |
|
} |
|
|
|
static inline void |
|
freePkt(struct tagPkt * __restrict p) |
|
{ |
|
if (!p) |
|
return; |
|
|
|
io_freeVar(&p->pkt_data); |
|
io_free(p); |
|
} |
|
|
|
static void * |
|
sendPacket(sched_task_t *task) |
|
{ |
|
struct tagPkt *p = TASK_ARG(task); |
|
register int n, slen; |
|
u_char *pos; |
|
|
|
if (!p || !p->pkt_data || AIT_ISEMPTY(p->pkt_data)) { |
|
ioDEBUG(9, "Error:: invalid packet or found empty content ..."); |
|
return NULL; |
|
} |
|
|
|
for (slen = AIT_LEN(p->pkt_data), pos = AIT_GET_BUF(p->pkt_data); slen > 0; |
|
slen -= n, pos += n) { |
|
n = send(TASK_FD(task), pos, slen, MSG_NOSIGNAL); |
|
if (n == -1) { |
|
ioSYSERR(0); |
|
break; |
|
} |
|
} |
|
|
|
freePkt(p); |
|
return NULL; |
|
} |
|
|
|
|
static int |
static int |
pubOnce(struct tagSession *sess, u_short mid, char * __restrict psTopic, |
pubOnce(struct tagSession *sess, u_short mid, char * __restrict psTopic, |
int topicLen, char * __restrict data, int datlen) |
int topicLen, char * __restrict data, int datlen) |
Line 133 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
Line 194 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
struct tagStore *store; |
struct tagStore *store; |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
void *ptr; |
void *ptr; |
|
struct tagPkt *p = NULL; |
|
|
ioTRACE(2); |
ioTRACE(2); |
|
|
Line 155 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
Line 217 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
} |
} |
if (call.WritePUB_subscribe(&cfg, pub, sess->sess_cid, mid, buf, |
if (call.WritePUB_subscribe(&cfg, pub, sess->sess_cid, mid, buf, |
sess->sess_user, sess->sess_addr, subs[i].sub_ret) > 0) { |
sess->sess_user, sess->sess_addr, subs[i].sub_ret) > 0) { |
store = malloc(sizeof(struct tagStore)); | store = io_malloc(sizeof(struct tagStore)); |
if (!store) { |
if (!store) { |
ioSYSERR(0); |
ioSYSERR(0); |
goto end; |
goto end; |
Line 198 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
Line 260 cmdSUBSCRIBE(void *srv, int len, void *arg)
|
if (siz == -1) { |
if (siz == -1) { |
ioDEBUG(5, "Error:: in msgSUBACK #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
ioDEBUG(5, "Error:: in msgSUBACK #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
goto end; |
goto end; |
} | } else { |
if ((siz = send(sess->sess_sock, sess->sess_buf->msg_base, siz, MSG_NOSIGNAL)) == -1) | p = mkPkt(sess->sess_buf->msg_base, siz); |
ioSYSERR(0); | |
else { | |
ioDEBUG(5, "Sended %d bytes.", siz); | |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
} |
} |
|
|
|
schedWrite(root, sendPacket, p, sess->sess_sock, NULL, 0); |
end: |
end: |
mqtt_subFree(&subs); |
mqtt_subFree(&subs); |
return 0; |
return 0; |
Line 219 cmdUNSUBSCRIBE(void *srv, int len, void *arg)
|
Line 280 cmdUNSUBSCRIBE(void *srv, int len, void *arg)
|
u_short mid = 0; |
u_short mid = 0; |
register int i; |
register int i; |
struct tagStore *store, *tmp; |
struct tagStore *store, *tmp; |
|
struct tagPkt *p = NULL; |
|
|
ioTRACE(2); |
ioTRACE(2); |
|
|
Line 245 cmdUNSUBSCRIBE(void *srv, int len, void *arg)
|
Line 307 cmdUNSUBSCRIBE(void *srv, int len, void *arg)
|
free(store->st_subscr.sub_topic.msg_base); |
free(store->st_subscr.sub_topic.msg_base); |
if (store->st_subscr.sub_value.msg_base) |
if (store->st_subscr.sub_value.msg_base) |
free(store->st_subscr.sub_value.msg_base); |
free(store->st_subscr.sub_value.msg_base); |
free(store); | io_free(store); |
} |
} |
} |
} |
|
|
Line 258 cmdUNSUBSCRIBE(void *srv, int len, void *arg)
|
Line 320 cmdUNSUBSCRIBE(void *srv, int len, void *arg)
|
if (siz == -1) { |
if (siz == -1) { |
ioDEBUG(5, "Error:: in msgUNSUBACK #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
ioDEBUG(5, "Error:: in msgUNSUBACK #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
goto end; |
goto end; |
} | } else { |
if ((siz = send(sess->sess_sock, sess->sess_buf->msg_base, siz, MSG_NOSIGNAL)) == -1) | p = mkPkt(sess->sess_buf->msg_base, siz); |
ioSYSERR(0); | |
else { | |
ioDEBUG(5, "Sended %d bytes.", siz); | |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
} |
} |
|
|
|
schedWrite(root, sendPacket, p, sess->sess_sock, NULL, 0); |
end: |
end: |
mqtt_subFree(&subs); |
mqtt_subFree(&subs); |
return 0; |
return 0; |
Line 275 cmdPINGREQ(void *srv, int len, void *arg)
|
Line 336 cmdPINGREQ(void *srv, int len, void *arg)
|
{ |
{ |
struct tagSession *sess = (struct tagSession*) arg; |
struct tagSession *sess = (struct tagSession*) arg; |
int siz = 0; |
int siz = 0; |
|
struct tagPkt *p = NULL; |
|
|
ioTRACE(2); |
ioTRACE(2); |
|
|
Line 286 cmdPINGREQ(void *srv, int len, void *arg)
|
Line 348 cmdPINGREQ(void *srv, int len, void *arg)
|
if (siz == -1) { |
if (siz == -1) { |
ioDEBUG(5, "Error:: in msgPINGRESP #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
ioDEBUG(5, "Error:: in msgPINGRESP #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
return 0; |
return 0; |
} |
|
if ((siz = send(sess->sess_sock, sess->sess_buf->msg_base, siz, MSG_NOSIGNAL)) == -1) { |
|
ioSYSERR(0); |
|
return 0; |
|
} else { |
} else { |
ioDEBUG(5, "Sended %d bytes.", siz); | p = mkPkt(sess->sess_buf->msg_base, siz); |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
memset(sess->sess_buf->msg_base, 0, sess->sess_buf->msg_len); |
} |
} |
|
|
|
schedWrite(root, sendPacket, p, sess->sess_sock, NULL, 0); |
return 0; |
return 0; |
} |
} |
|
|
Line 302 int
|
Line 361 int
|
cmdCONNECT(void *srv, int len, void *arg) |
cmdCONNECT(void *srv, int len, void *arg) |
{ |
{ |
struct tagStore *store; |
struct tagStore *store; |
|
struct tagPkt *p; |
struct tagSession *sess = (struct tagSession*) arg; |
struct tagSession *sess = (struct tagSession*) arg; |
|
|
ioTRACE(2); |
ioTRACE(2); |
Line 329 cmdCONNECT(void *srv, int len, void *arg)
|
Line 389 cmdCONNECT(void *srv, int len, void *arg)
|
if (store->st_subscr.sub_value.msg_base) |
if (store->st_subscr.sub_value.msg_base) |
free(store->st_subscr.sub_value.msg_base); |
free(store->st_subscr.sub_value.msg_base); |
|
|
free(store); | io_free(store); |
| } |
| |
| while ((p = SLIST_FIRST(&sess->sess_sndpkt))) { |
| SLIST_REMOVE_HEAD(&sess->sess_sndpkt, pkt_node); |
| |
| io_freeVar(&p->pkt_data); |
| io_free(p); |
} |
} |
|
|
if (sess->sess_will.msg) |
if (sess->sess_will.msg) |