version 1.2.2.9, 2012/05/27 10:04:05
|
version 1.2.2.12, 2012/06/19 08:32:17
|
Line 8 io_enableDEBUG;
|
Line 8 io_enableDEBUG;
|
|
|
extern char compiled[], compiledby[], compilehost[]; |
extern char compiled[], compiledby[], compilehost[]; |
volatile intptr_t Kill; |
volatile intptr_t Kill; |
|
sched_root_task_t *root; |
|
|
struct tagArgs *args; |
struct tagArgs *args; |
|
|
Line 56 Subscribe(int sock, FILE *lf)
|
Line 57 Subscribe(int sock, FILE *lf)
|
u_short mid; |
u_short mid; |
mqtt_subscr_t *sub; |
mqtt_subscr_t *sub; |
|
|
|
#ifdef __NetBSD__ |
|
srandom(getpid() ^ time(NULL)); |
|
#else |
srandomdev(); |
srandomdev(); |
|
#endif |
mid = random() % USHRT_MAX; |
mid = random() % USHRT_MAX; |
|
|
printf(" > Execute SUBSCRIBE request #%d ... ", mid); |
printf(" > Execute SUBSCRIBE request #%d ... ", mid); |
Line 80 Unsubscribe(int sock)
|
Line 85 Unsubscribe(int sock)
|
{ |
{ |
u_short mid; |
u_short mid; |
|
|
|
#ifdef __NetBSD__ |
|
srandom(getpid() ^ time(NULL)); |
|
#else |
srandomdev(); |
srandomdev(); |
|
#endif |
mid = random() % USHRT_MAX; |
mid = random() % USHRT_MAX; |
|
|
printf(" > Execute UNSUBSCRIBE request #%d ... ", mid); |
printf(" > Execute UNSUBSCRIBE request #%d ... ", mid); |
Line 94 Unsubscribe(int sock)
|
Line 103 Unsubscribe(int sock)
|
} |
} |
|
|
|
|
|
static void * |
|
pubRX(sched_task_t *task) |
|
{ |
|
int siz, rlen; |
|
char szTopic[BUFSIZ] = { 0 }; |
|
void *data = NULL; |
|
u_short mid; |
|
|
|
rlen = RecvFrom(TASK_FD(task)); |
|
if (siz == -1) |
|
goto end; |
|
siz = mqtt_readPUBLISH(args->msg->msg_base, szTopic, sizeof szTopic, &mid, &data); |
|
if (siz == -1) |
|
goto end; |
|
|
|
fprintf(TASK_ARG(task), "\nMessage ID: 0x%04hu\n", mid); |
|
|
|
if (data) { |
|
fputs((const char*) data, TASK_ARG(task)); |
|
free(data); |
|
} |
|
end: |
|
schedReadSelf(task); |
|
return NULL; |
|
} |
|
|
|
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
Line 173 main(int argc, char **argv)
|
Line 209 main(int argc, char **argv)
|
sub->sub_ret = (u_char) *str; |
sub->sub_ret = (u_char) *str; |
} else |
} else |
sub->sub_ret = (u_char) args->QoS; |
sub->sub_ret = (u_char) args->QoS; |
sub->sub_topic.msg_base = io_strdup(szStr); | sub->sub_topic.msg_base = strdup(szStr); |
sub->sub_topic.msg_len = strlen(szStr); |
sub->sub_topic.msg_len = strlen(szStr); |
break; |
break; |
case 'q': |
case 'q': |
Line 272 main(int argc, char **argv)
|
Line 308 main(int argc, char **argv)
|
else |
else |
lf = stdout; |
lf = stdout; |
if (lf) { |
if (lf) { |
|
root = schedBegin(); |
|
|
ret = Subscribe(args->cli->sock, lf); |
ret = Subscribe(args->cli->sock, lf); |
|
|
|
schedRead(root, pubRX, lf, args->cli->sock, NULL, 0); |
|
schedRun(root, &Kill); |
|
|
if (un) |
if (un) |
Unsubscribe(args->cli->sock); |
Unsubscribe(args->cli->sock); |
fclose(lf); |
fclose(lf); |
|
|
|
schedEnd(&root); |
} else |
} else |
printf("Error:: in subscribe file #%d - %s\n", errno, strerror(errno)); |
printf("Error:: in subscribe file #%d - %s\n", errno, strerror(errno)); |
} else |
} else |