mongoose/docs/mqtt-broker.adoc
Marko Mikulicic f443c64341 Temporarily disable appdash from docker-compose
Until I read the doc and find how to limit the retention,
otherwise it just eats all my ram and cpu and things start to fall
apart.

PUBLISHED_FROM=eb33fb44736f07b992270689217aca4af70513ff
2016-05-15 22:07:04 +03:00

83 lines
2.0 KiB
Plaintext

=== MQTT Broker
==== struct mg_mqtt_session
[source,c]
----
struct mg_mqtt_session {
struct mg_mqtt_broker *brk; /* Broker */
struct mg_mqtt_session *next, *prev; /* mg_mqtt_broker::sessions linkage */
struct mg_connection *nc; /* Connection with the client */
size_t num_subscriptions; /* Size of `subscriptions` array */
struct mg_mqtt_topic_expression *subscriptions;
void *user_data; /* User data */
};
----
MQTT session (Broker side).
==== struct mg_mqtt_broker
[source,c]
----
struct mg_mqtt_broker {
struct mg_mqtt_session *sessions; /* Session list */
void *user_data; /* User data */
};
----
MQTT broker.
==== mg_mqtt_broker_init()
[source,c]
----
void mg_mqtt_broker_init(struct mg_mqtt_broker *brk, void *user_data);
----
Initialize a MQTT broker.
==== mg_mqtt_broker()
[source,c]
----
void mg_mqtt_broker(struct mg_connection *brk, int ev, void *data);
----
Process a MQTT broker message.
Listening connection expects a pointer to an initialized `mg_mqtt_broker`
structure in the `user_data` field.
Basic usage:
```c
mg_mqtt_broker_init(&brk, NULL);
if ((nc = mg_bind(&mgr, address, mg_mqtt_broker)) == NULL) {
// fail;
}
nc->user_data = &brk;
```
New incoming connections will receive a `mg_mqtt_session` structure
in the connection `user_data`. The original `user_data` will be stored
in the `user_data` field of the session structure. This allows the user
handler to store user data before `mg_mqtt_broker` creates the session.
Since only the MG_EV_ACCEPT message is processed by the listening socket,
for most events the `user_data` will thus point to a `mg_mqtt_session`.
==== mg_mqtt_next()
[source,c]
----
struct mg_mqtt_session *mg_mqtt_next(struct mg_mqtt_broker *brk,
struct mg_mqtt_session *s);
----
Iterate over all mqtt sessions connections. Example:
```c
struct mg_mqtt_session *s;
for (s = mg_mqtt_next(brk, NULL); s != NULL; s = mg_mqtt_next(brk, s)) {
// Do something
}
```