|
version 1.1.2.4, 2011/12/01 08:15:25
|
version 1.1.2.10, 2011/12/08 14:52:47
|
|
Line 1
|
Line 1
|
| #include "global.h" |
#include "global.h" |
| |
|
| |
|
| static int | extern char cliCmd[], *cliStr[]; |
| startSession(int s, const char *csAddr) | |
| | |
| | static void * |
| | startSession(sched_task_t *task) |
| { |
{ |
| return 0; | static u_char basebuf[USHRT_MAX]; |
| | mqtt_cb_t cbs[MQTT_TYPE_MAX + 1] = { 0 }; |
| | mqtt_msg_t *buf = { basebuf, sizeof basebuf }; |
| | mqtthdr_connflgs_t flg; |
| | int ret = 0; |
| | struct timeval tv = { 0 }; |
| | u_short ka; |
| | |
| | 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), basebuf, sizeof basebuf, 0) == -1) { |
| | VERB(3) syslog(LOG_ERR, "Error:: recv(%d) #%d - %s", (int) TASK_FD(task), |
| | errno, strerror(errno)); |
| | goto end; |
| | } |
| | |
| | flg = mqtt_readCONNECT(buf, &ka, ); |
| | if (flg.reserved) { |
| | VERB(3) syslog(LOG_ERR, "Error:: in MQTT protocol #%d - %s", |
| | mqtt_GetErrno(), mqtt_GetError()); |
| | goto end; |
| | } |
| | |
| | /* |
| | for (ret = i = 0; cliCmd[i] && !(ret = (hdr->mqtt_msg.type == cliCmd[i])); i++); |
| | if (!ret) { |
| | VERB(2) syslog(LOG_ERR, "Error:: wrong command type #%d %s", |
| | hdr->mqtt_msg.type, cliStr[i]); |
| | goto end; |
| | } |
| | */ |
| | |
| | /* check online table for user */ |
| | // ChkSessPUB(&cfg, ); |
| | |
| | // 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)); |
| | VERB(1) syslog(LOG_DEBUG, "Close client %s with socket=%d", |
| | (char*) TASK_ARG(task), (int) TASK_FD(task)); |
| | if (TASK_ARG(task)) |
| | free(TASK_ARG(task)); |
| | return NULL; |
| } |
} |
| |
|
| /* ----------------------------------------------------------------------- */ |
/* ----------------------------------------------------------------------- */ |
| |
|
| |
static void * |
| |
thrSched(void *arg __unused) |
| |
{ |
| |
FTRACE(1); |
| |
|
| |
schedRun(root, (intptr_t*) &Kill); |
| |
pthread_exit(NULL); |
| |
} |
| |
|
| int |
int |
| Run(int sock) |
Run(int sock) |
| { |
{ |
| io_sockaddr_t sa; |
io_sockaddr_t sa; |
| socklen_t sslen = sizeof sa.ss; |
socklen_t sslen = sizeof sa.ss; |
| int cli; |
int cli; |
| char szAddr[STRSIZ] = { 0 }; | char *str = NULL, szAddr[STRSIZ] = { 0 }; |
| | pthread_t tid; |
| |
|
| FTRACE(1); |
FTRACE(1); |
| |
|
| |
if (pthread_create(&tid, NULL, thrSched, NULL)) { |
| |
syslog(LOG_ERR, "Error:: thread scheduler #%d - %s", errno, strerror(errno)); |
| |
return -1; |
| |
} else |
| |
pthread_detach(tid); |
| |
VERB(2) syslog(LOG_DEBUG, "Run scheduler management thread"); |
| |
|
| if (listen(sock, SOMAXCONN) == -1) { |
if (listen(sock, SOMAXCONN) == -1) { |
| syslog(LOG_ERR, "Error:: listen(%d) #%d - %s\n", sock, errno, strerror(errno)); |
syslog(LOG_ERR, "Error:: listen(%d) #%d - %s\n", sock, errno, strerror(errno)); |
| |
pthread_cancel(tid); |
| return -1; |
return -1; |
| } |
} |
| |
|
|
Line 50 Run(int sock)
|
Line 133 Run(int sock)
|
| sa.sa.sa_family); |
sa.sa.sa_family); |
| continue; |
continue; |
| } |
} |
| syslog(LOG_DEBUG, "Connected client with socket=%d from %s", cli, szAddr); | str = strdup(szAddr); |
| | syslog(LOG_DEBUG, "Connected client with socket=%d from %s", cli, str); |
| } |
} |
| |
|
| if (startSession(cli, szAddr)) { | if (!schedRead(root, startSession, str, cli)) { |
| close(cli); |
close(cli); |
| VERB(1) syslog(LOG_DEBUG, "Terminated client with socket=%d", cli); |
VERB(1) syslog(LOG_DEBUG, "Terminated client with socket=%d", cli); |
| continue; | if (str) |
| | free(str); |
| } |
} |
| } |
} |
| |
|