version 1.2.2.16, 2012/04/26 07:25:00
|
version 1.2.2.17, 2012/04/26 08:20:20
|
Line 23 initSession(int sock, ait_val_t * __restrict v)
|
Line 23 initSession(int sock, ait_val_t * __restrict v)
|
sess = malloc(sizeof(struct tagSession)); |
sess = malloc(sizeof(struct tagSession)); |
if (!sess) { |
if (!sess) { |
ioSYSERR(0); |
ioSYSERR(0); |
io_freeVar(v); |
|
return NULL; |
return NULL; |
} else |
} else |
memset(sess, 0, sizeof(struct tagSession)); |
memset(sess, 0, sizeof(struct tagSession)); |
Line 42 initSession(int sock, ait_val_t * __restrict v)
|
Line 41 initSession(int sock, ait_val_t * __restrict v)
|
if (!sess->sess_buf) { |
if (!sess->sess_buf) { |
ioLIBERR(mqtt); |
ioLIBERR(mqtt); |
free(sess); |
free(sess); |
io_freeVar(v); |
|
return NULL; |
return NULL; |
} |
} |
|
|
Line 52 initSession(int sock, ait_val_t * __restrict v)
|
Line 50 initSession(int sock, ait_val_t * __restrict v)
|
ioDEBUG(3, "Error:: in srv_Init #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
ioDEBUG(3, "Error:: in srv_Init #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
mqtt_msgFree(&sess->sess_buf, 42); |
mqtt_msgFree(&sess->sess_buf, 42); |
free(sess); |
free(sess); |
io_freeVar(v); |
|
return NULL; |
return NULL; |
} else { |
} else { |
mqtt_srv_setCmd(sess->sess_srv, MQTT_TYPE_CONNECT, cmdCONNECT); |
mqtt_srv_setCmd(sess->sess_srv, MQTT_TYPE_CONNECT, cmdCONNECT); |
Line 66 initSession(int sock, ait_val_t * __restrict v)
|
Line 63 initSession(int sock, ait_val_t * __restrict v)
|
|
|
sess->sess_sock = sock; |
sess->sess_sock = sock; |
strlcpy(sess->sess_addr, (char*) AIT_GET_STR(v), sizeof sess->sess_addr); |
strlcpy(sess->sess_addr, (char*) AIT_GET_STR(v), sizeof sess->sess_addr); |
io_freeVar(v); |
|
return sess; |
return sess; |
} |
} |
|
|
Line 84 finiSession(struct tagSession *sess)
|
Line 80 finiSession(struct tagSession *sess)
|
call.FiniSessPUB(&cfg, pub, sess->sess_cid, sess->sess_user, "%"); |
call.FiniSessPUB(&cfg, pub, sess->sess_cid, sess->sess_user, "%"); |
|
|
SESS_ELEM_LOCK(sess); |
SESS_ELEM_LOCK(sess); |
|
|
while ((store = SLIST_FIRST(&sess->sess_subscr))) { |
while ((store = SLIST_FIRST(&sess->sess_subscr))) { |
SLIST_REMOVE_HEAD(&sess->sess_subscr, st_node); |
SLIST_REMOVE_HEAD(&sess->sess_subscr, st_node); |
|
|
Line 143 thrSession(struct tagSession *sess)
|
Line 138 thrSession(struct tagSession *sess)
|
int ret, locKill = 42; |
int ret, locKill = 42; |
struct pollfd pfd; |
struct pollfd pfd; |
struct mqtthdr *hdr; |
struct mqtthdr *hdr; |
ait_val_t *v; |
|
|
|
pthread_cleanup_push((void(*)(void*)) stopSession, sess); |
pthread_cleanup_push((void(*)(void*)) stopSession, sess); |
ioTRACE(2); |
ioTRACE(2); |
Line 175 thrSession(struct tagSession *sess)
|
Line 169 thrSession(struct tagSession *sess)
|
ioLIBERR(mqtt); |
ioLIBERR(mqtt); |
switch (hdr->mqtt_msg.type) { |
switch (hdr->mqtt_msg.type) { |
case MQTT_TYPE_CONNECT: |
case MQTT_TYPE_CONNECT: |
ioDEBUG(5, "Exec CONNECT session"); | schedEvent(root, startSession, NULL, (u_long) sess->sess_sock, sess, ret); |
if ((v = io_allocVar())) { | |
AIT_SET_STR(v, sess->sess_addr); | |
if (!schedEvent(root, startSession, v, (u_long) sess->sess_sock, sess, ret)) | |
io_freeVar(v); | |
} else | |
ioLIBERR(mqtt); | |
| |
SESS_LOCK; | |
TAILQ_REMOVE(&Sessions, sess, sess_node); | |
SESS_UNLOCK; | |
| |
locKill ^= locKill; |
locKill ^= locKill; |
break; |
break; |
case MQTT_TYPE_DISCONNECT: |
case MQTT_TYPE_DISCONNECT: |
/* |
|
ioDEBUG(5, "Exec DISCONNECT session"); |
|
SESS_LOCK; |
|
TAILQ_REMOVE(&Sessions, sess, sess_node); |
|
SESS_UNLOCK; |
|
*/ |
|
|
|
finiSession(sess); |
finiSession(sess); |
locKill ^= locKill; |
locKill ^= locKill; |
continue; |
continue; |
Line 248 startSession(sched_task_t *task)
|
Line 224 startSession(sched_task_t *task)
|
if (!TASK_DATA(task)) { |
if (!TASK_DATA(task)) { |
/* flow from accept new clients */ |
/* flow from accept new clients */ |
sess = initSession(TASK_FD(task), TASK_ARG(task)); |
sess = initSession(TASK_FD(task), TASK_ARG(task)); |
|
io_freeVar(TASK_ARG(task)); |
if (!sess) { |
if (!sess) { |
io_freeVar(TASK_ARG(task)); |
|
close(TASK_FD(task)); |
close(TASK_FD(task)); |
return NULL; |
return NULL; |
} |
} |
Line 375 acceptClient(sched_task_t *task)
|
Line 351 acceptClient(sched_task_t *task)
|
} else { |
} else { |
memset(str, 0, sizeof str); |
memset(str, 0, sizeof str); |
snprintf(str, sizeof str, "%s:%hu", io_n2addr(&sa, v), io_n2port(&sa)); |
snprintf(str, sizeof str, "%s:%hu", io_n2addr(&sa, v), io_n2port(&sa)); |
|
AIT_FREE_VAL(v); |
AIT_SET_STR(v, str); |
AIT_SET_STR(v, str); |
} |
} |
ioDEBUG(1, "Connected client with socket=%d from %s", cli, AIT_GET_STR(v)); |
ioDEBUG(1, "Connected client with socket=%d from %s", cli, AIT_GET_STR(v)); |
Line 417 Run(int sock)
|
Line 394 Run(int sock)
|
|
|
schedPolling(root, &pl, NULL); |
schedPolling(root, &pl, NULL); |
schedRun(root, &Kill); |
schedRun(root, &Kill); |
|
sleep(1); |
|
|
pthread_attr_destroy(&attr); |
pthread_attr_destroy(&attr); |
|
|