version 1.1.2.5, 2011/12/01 08:45:01
|
version 1.1.2.6, 2011/12/01 14:41:11
|
Line 4
|
Line 4
|
static void * |
static void * |
startSession(sched_task_t *task) |
startSession(sched_task_t *task) |
{ |
{ |
|
mqtt_msg_t *buf; |
|
mqtt_cb_t cbs[MQTT_TYPE_MAX + 1] = { 0 }; |
|
int ret = 0; |
|
|
|
FTRACE(4); |
|
|
|
buf = mqtt_msgAlloc(USHRT_MAX); |
|
if (!buf) { |
|
syslog(LOG_ERR, "Error:: allocate message buf (%d) #%d - %s", (int) TASK_FD(task), |
|
mqtt_GetErrno(), mqtt_GetError()); |
|
goto end; |
|
} |
|
|
|
if (recv(TASK_FD(task), buf->msg_base, buf->msg_len, 0) == -1) { |
|
syslog(LOG_ERR, "Error:: recv(%d) #%d - %s", (int) TASK_FD(task), |
|
errno, strerror(errno)); |
|
mqtt_msgFree(&buf, 42); |
|
goto end; |
|
} |
|
|
|
ret = mqttDispatcher(cbs, buf); |
|
|
|
mqtt_msgFree(&buf, 42); |
|
|
|
switch (ret) { |
|
case -1: |
|
syslog(LOG_ERR, "Error:: in MQTT protocol #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
|
break; |
|
default: |
|
return NULL; |
|
} |
|
end: /* close client connection */ |
close(TASK_FD(task)); |
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)) |
if (TASK_ARG(task)) |
free(TASK_ARG(task)); |
free(TASK_ARG(task)); |
return 0; | return NULL; |
} |
} |
|
|
/* ----------------------------------------------------------------------- */ |
/* ----------------------------------------------------------------------- */ |