Commit 0bb14abb authored by Sergey Lyubka's avatar Sergey Lyubka Committed by Cesanta Bot

Nitpick for MQTT example

PUBLISHED_FROM=a0dd26c00b41363f1cc58c28f530fbdf272ed146
parent 4c37e492
PROG = mqtt_broker PROG = mqtt_broker
MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER -DMG_ENABLE_HTTP=0 MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER -DMG_ENABLE_HTTP=0
SSL_LIB=openssl #SSL_LIB=openssl
include ../examples.mk include ../examples.mk
...@@ -17,22 +17,31 @@ ...@@ -17,22 +17,31 @@
#include "../../mongoose.h" #include "../../mongoose.h"
static const char *s_listening_address = "0.0.0.0:1883";
static void ev_handler(struct mg_connection *c, int ev, void *ev_data) {
if (ev != MG_EV_POLL) printf("USER HANDLER GOT EVENT %d\n", ev);
/* Do your custom event processing here */
mg_mqtt_broker(c, ev, ev_data);
}
int main(void) { int main(void) {
struct mg_mgr mgr; struct mg_mgr mgr;
const char *address = "0.0.0.0:1883"; struct mg_connection *c;
struct mg_connection *nc;
struct mg_mqtt_broker brk; struct mg_mqtt_broker brk;
mg_mgr_init(&mgr, NULL); mg_mgr_init(&mgr, NULL);
mg_mqtt_broker_init(&brk, NULL); mg_mqtt_broker_init(&brk, NULL);
if ((nc = mg_bind(&mgr, address, mg_mqtt_broker)) == NULL) { if ((c = mg_bind(&mgr, s_listening_address, ev_handler)) == NULL) {
fprintf(stderr, "mg_bind(%s) failed\n", address); fprintf(stderr, "mg_bind(%s) failed\n", s_listening_address);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
nc->user_data = &brk; mg_mqtt_broker_init(&brk, NULL);
c->user_data = &brk;
mg_set_protocol_mqtt(c);
printf("MQTT broker started on %s\n", address); printf("MQTT broker started on %s\n", s_listening_address);
/* /*
* TODO: Add a HTTP status page that shows current sessions * TODO: Add a HTTP status page that shows current sessions
......
...@@ -27,10 +27,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -27,10 +27,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
struct mg_mqtt_message *msg = (struct mg_mqtt_message *) p; struct mg_mqtt_message *msg = (struct mg_mqtt_message *) p;
(void) nc; (void) nc;
#if 0 if (ev != MG_EV_POLL) printf("USER HANDLER GOT EVENT %d\n", ev);
if (ev != MG_EV_POLL)
printf("USER HANDLER GOT %d\n", ev);
#endif
switch (ev) { switch (ev) {
case MG_EV_CONNECT: { case MG_EV_CONNECT: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment