version 1.1.2.14, 2011/12/09 13:43:55
|
version 1.1.2.15, 2011/12/09 14:01:37
|
Line 11 initSession(int sock, char * __restrict addr)
|
Line 11 initSession(int sock, char * __restrict addr)
|
struct tagSession *sess = NULL; |
struct tagSession *sess = NULL; |
const char *str; |
const char *str; |
|
|
|
FTRACE(5); |
|
|
if (!addr) |
if (!addr) |
return NULL; |
return NULL; |
|
|
sess = malloc(sizeof(struct tagSession)); |
sess = malloc(sizeof(struct tagSession)); |
if (!sess) { |
if (!sess) { |
VERB(3) syslog(LOG_ERR, "Error:: in malloc #%d - %s", errno, strerror(errno)); |
VERB(3) syslog(LOG_ERR, "Error:: in malloc #%d - %s", errno, strerror(errno)); |
free(addr); |
|
return NULL; |
return NULL; |
} else |
} else |
memset(sess, 0, sizeof(struct tagSession)); |
memset(sess, 0, sizeof(struct tagSession)); |
Line 28 initSession(int sock, char * __restrict addr)
|
Line 29 initSession(int sock, char * __restrict addr)
|
else |
else |
sess->sess_retry = strtol(str, NULL, 0); |
sess->sess_retry = strtol(str, NULL, 0); |
|
|
sess->sess_sock = sock; |
|
strlcpy(sess->sess_addr, addr, sizeof sess->sess_addr); |
|
free(addr); |
|
|
|
sess->sess_buf = mqtt_msgAlloc(0); |
sess->sess_buf = mqtt_msgAlloc(0); |
if (!sess->sess_buf) { |
if (!sess->sess_buf) { |
VERB(3) syslog(LOG_ERR, "Error:: in msgAlloc #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
VERB(3) syslog(LOG_ERR, "Error:: in msgAlloc #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
Line 39 initSession(int sock, char * __restrict addr)
|
Line 36 initSession(int sock, char * __restrict addr)
|
return NULL; |
return NULL; |
} |
} |
|
|
|
sess->sess_sock = sock; |
|
strlcpy(sess->sess_addr, addr, sizeof sess->sess_addr); |
|
free(addr); |
return sess; |
return sess; |
} |
} |
|
|
Line 48 finiSession(struct tagSession *sess)
|
Line 48 finiSession(struct tagSession *sess)
|
register int i; |
register int i; |
struct tagStore *store; |
struct tagStore *store; |
|
|
|
FTRACE(5); |
|
|
if (!sess) |
if (!sess) |
return; |
return; |
|
|
Line 75 finiSession(struct tagSession *sess)
|
Line 77 finiSession(struct tagSession *sess)
|
} |
} |
|
|
static void * |
static void * |
|
thrSession(struct tagSession *sess) |
|
{ |
|
FTRACE(2); |
|
|
|
TAILQ_REMOVE(&Sessions, sess, sess_node); |
|
pthread_exit(NULL); |
|
return NULL; |
|
} |
|
|
|
static void * |
startSession(sched_task_t *task) |
startSession(sched_task_t *task) |
{ |
{ |
u_char basebuf[USHRT_MAX]; |
u_char basebuf[USHRT_MAX]; |
mqtt_cb_t cbs[MQTT_TYPE_MAX + 1] = { 0 }; |
|
mqtt_msg_t buf = { basebuf, sizeof basebuf }; |
mqtt_msg_t buf = { basebuf, sizeof basebuf }; |
mqtthdr_connflgs_t flg; |
mqtthdr_connflgs_t flg; |
mqtthdr_connack_t cack; |
mqtthdr_connack_t cack; |
int ret = 0; |
|
struct timeval tv = { 0 }; |
|
struct tagSession *sess = NULL; |
struct tagSession *sess = NULL; |
|
|
FTRACE(4); |
FTRACE(4); |
|
|
sess = initSession(TASK_FD(task), TASK_ARG(task)); |
sess = initSession(TASK_FD(task), TASK_ARG(task)); |
if (!sess) | if (!sess) { |
| if (TASK_ARG(task)) |
| free(TASK_ARG(task)); |
| close(TASK_FD(task)); |
return NULL; |
return NULL; |
|
} |
|
|
if (recv(sess->sess_sock, buf.msg_base, buf.msg_len, 0) == -1) { |
if (recv(sess->sess_sock, buf.msg_base, buf.msg_len, 0) == -1) { |
VERB(3) syslog(LOG_ERR, "Error:: recv(%d) #%d - %s", sess->sess_sock, errno, strerror(errno)); |
VERB(3) syslog(LOG_ERR, "Error:: recv(%d) #%d - %s", sess->sess_sock, errno, strerror(errno)); |
Line 112 startSession(sched_task_t *task)
|
Line 125 startSession(sched_task_t *task)
|
|
|
/* check online table for user */ |
/* check online table for user */ |
|
|
|
/* Start session thread OK ... */ |
|
TAILQ_INSERT_TAIL(&Sessions, sess, sess_node); |
|
pthread_create(&sess->sess_tid, NULL, (void*(*)(void*)) thrSession, sess); |
|
pthread_detach(sess->sess_tid); |
|
VERB(1) syslog(LOG_DEBUG, "ConnID=%s(%s) for %s login OK!", |
|
sess->sess_cid, sess->sess_user, sess->sess_addr); |
|
return NULL; |
end: /* close client connection */ |
end: /* close client connection */ |
if (sess) |
|
free(sess); |
|
close(TASK_FD(task)); |
|
VERB(1) syslog(LOG_DEBUG, "Close client %s with socket=%d", |
VERB(1) syslog(LOG_DEBUG, "Close client %s with socket=%d", |
(char*) TASK_ARG(task), (int) TASK_FD(task)); |
(char*) TASK_ARG(task), (int) TASK_FD(task)); |
if (TASK_ARG(task)) | finiSession(sess); |
free(TASK_ARG(task)); | |
return NULL; |
return NULL; |
} |
} |
|
|