|
libwebsockets
Lightweight C library for HTML5 websockets
|
Go to the source code of this file.
Data Structures | |
| union | lws_mqtt_fixed_hdr_t |
| struct | lws_mqtt_qos2_state_ops |
| struct | lws_mqtt_client_connect_param_s |
| struct | lws_mqtt_publish_param_s |
| struct | topic_elem |
| struct | lws_mqtt_subscribe_param_s |
| struct | lws_mqtt_fixed_hdr_t.flags |
| struct | lws_mqtt_client_connect_param_s.will_param |
| struct | lws_mqtt_client_connect_param_s.birth_param |
Typedefs | |
| typedef struct _lws_mqtt_related | lws_mqtt_related_t |
| typedef struct lws_mqtt_str_st | lws_mqtt_str_t |
| typedef struct lws_mqtt_qos2_state_ops | lws_mqtt_qos2_state_ops_t |
| typedef struct lws_mqtt_client_connect_param_s | lws_mqtt_client_connect_param_t |
| typedef struct lws_mqtt_publish_param_s | lws_mqtt_publish_param_t |
| typedef struct topic_elem | lws_mqtt_topic_elem_t |
| typedef struct lws_mqtt_subscribe_param_s | lws_mqtt_subscribe_param_t |
| struct lws_mqtt_publish_param_s |
Definition at line 137 of file lws-mqtt.h.
| Data Fields | ||
|---|---|---|
| char * | topic | |
| uint16_t | topic_len | |
| const void * | payload | |
| uint32_t | payload_len | |
| uint32_t | payload_pos | |
| lws_mqtt_qos_levels_t | qos | |
| uint16_t | packet_id | |
| uint8_t | dup:1 | |
| uint8_t | retain:1 | |
| struct topic_elem |
Definition at line 154 of file lws-mqtt.h.
| Data Fields | ||
|---|---|---|
| const char * | name | |
| lws_mqtt_qos_levels_t | qos | |
| uint8_t | acked | |
| struct lws_mqtt_subscribe_param_s |
Definition at line 174 of file lws-mqtt.h.
| Data Fields | ||
|---|---|---|
| uint32_t | num_topics | |
| lws_mqtt_topic_elem_t * | topic | |
| uint16_t | packet_id | |
| struct lws_mqtt_fixed_hdr_t.flags |
| struct lws_mqtt_client_connect_param_s.will_param |
Definition at line 114 of file lws-mqtt.h.
| Data Fields | ||
|---|---|---|
| const char * | topic | |
| const char * | message | |
| lws_mqtt_qos_levels_t | qos | |
| uint8_t | retain | |
| struct lws_mqtt_client_connect_param_s.birth_param |
Definition at line 121 of file lws-mqtt.h.
| Data Fields | ||
|---|---|---|
| const char * | topic | |
| const char * | message | |
| lws_mqtt_qos_levels_t | qos | |
| uint8_t | retain | |
| #define MQTT_VER_3_1_1 4 |
Definition at line 35 of file lws-mqtt.h.
| #define MQTT_VER_STRING "3.1.1" |
Definition at line 37 of file lws-mqtt.h.
| #define LWS_MQTT_FINAL_PART 1 |
Definition at line 42 of file lws-mqtt.h.
| #define LWS_MQTT_MAX_AWSIOT_TOPICLEN 256 |
Definition at line 44 of file lws-mqtt.h.
| #define LWS_MQTT_MAX_TOPICLEN 65535 |
Definition at line 45 of file lws-mqtt.h.
| #define LWS_MQTT_MAX_PACKET_SIZE (1 * 1024 * 1024) |
Definition at line 46 of file lws-mqtt.h.
| #define LWS_MQTT_MAX_CIDLEN 128 |
Definition at line 47 of file lws-mqtt.h.
| #define LWS_MQTT_RANDOM_CIDLEN |
Definition at line 48 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_MAX_THING_LEN 128 |
Definition at line 50 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_MAX_SHADOW_LEN 64 |
Definition at line 51 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_UPDATE_STR "/update" |
Definition at line 52 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_DELETE_STR "/delete" |
Definition at line 53 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_GET_STR "/get" |
Definition at line 54 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_RESP_ACCEPTED_STR "/accepted" |
Definition at line 55 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_RESP_REJECTED_STR "/rejected" |
Definition at line 56 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_RESP_DELTA_STR "/delta" |
Definition at line 57 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_RESP_DOCUMENT_STR "/documents" |
Definition at line 58 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_UPDATE_ACCEPTED_STR LWS_MQTT_SHADOW_UPDATE_STR LWS_MQTT_SHADOW_RESP_ACCEPTED_STR |
Definition at line 59 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_UPDATE_REJECTED_STR LWS_MQTT_SHADOW_UPDATE_STR LWS_MQTT_SHADOW_RESP_REJECTED_STR |
Definition at line 60 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_UPDATE_DELTA_STR LWS_MQTT_SHADOW_UPDATE_STR LWS_MQTT_SHADOW_RESP_DELTA_STR |
Definition at line 61 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_UPDATE_DOCUMENT_STR LWS_MQTT_SHADOW_UPDATE_STR LWS_MQTT_SHADOW_RESP_DOCUMENT_STR |
Definition at line 62 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_DELETE_ACCEPTED_STR LWS_MQTT_SHADOW_DELETE_STR LWS_MQTT_SHADOW_RESP_ACCEPTED_STR |
Definition at line 63 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_DELETE_REJECTED_STR LWS_MQTT_SHADOW_DELETE_STR LWS_MQTT_SHADOW_RESP_REJECTED_STR |
Definition at line 64 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_GET_ACCEPTED_STR LWS_MQTT_SHADOW_GET_STR LWS_MQTT_SHADOW_RESP_ACCEPTED_STR |
Definition at line 65 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_GET_REJECTED_STR LWS_MQTT_SHADOW_GET_STR LWS_MQTT_SHADOW_RESP_REJECTED_STR |
Definition at line 66 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_PREFIX_FORMAT "$aws/things/%s" |
Definition at line 67 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_NAMED_SHADOW_TOPIC_FORMAT LWS_MQTT_SHADOW_PREFIX_FORMAT "/shadow/name/%s%s" |
Definition at line 68 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_UNNAMED_SHADOW_TOPIC_FORMAT LWS_MQTT_SHADOW_PREFIX_FORMAT "/shadow%s" |
Definition at line 69 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_UNNAMED_TOPIC_MATCH "$aws/things/+/shadow/+" |
Definition at line 70 of file lws-mqtt.h.
| #define LWS_MQTT_SHADOW_NAMED_TOPIC_MATCH "$aws/things/+/shadow/name/+/+" |
Definition at line 71 of file lws-mqtt.h.
| #define LWS_MQTT_MAX_TOPICS 8 |
Definition at line 169 of file lws-mqtt.h.
| typedef struct _lws_mqtt_related lws_mqtt_related_t |
Definition at line 31 of file lws-mqtt.h.
| typedef struct lws_mqtt_str_st lws_mqtt_str_t |
Definition at line 33 of file lws-mqtt.h.
| typedef struct lws_mqtt_qos2_state_ops lws_mqtt_qos2_state_ops_t |
| typedef struct lws_mqtt_client_connect_param_s lws_mqtt_client_connect_param_t |
| typedef struct lws_mqtt_publish_param_s lws_mqtt_publish_param_t |
| typedef struct topic_elem lws_mqtt_topic_elem_t |
| typedef struct lws_mqtt_subscribe_param_s lws_mqtt_subscribe_param_t |
| Enumerator | |
|---|---|
| QOS0 | |
| QOS1 | |
| QOS2 | |
| RESERVED_QOS_LEVEL | |
| FAILURE_QOS_LEVEL | |
Definition at line 73 of file lws-mqtt.h.
Definition at line 182 of file lws-mqtt.h.
Definition at line 202 of file lws-mqtt.h.
| Enumerator | |
|---|---|
| LMQCFT_SESSION_PRESENT | |
Definition at line 219 of file lws-mqtt.h.
| enum lws_mqtt_reason_t |
Definition at line 223 of file lws-mqtt.h.
| enum lws_mqtt_property |
Definition at line 276 of file lws-mqtt.h.
| LWS_VISIBLE LWS_EXTERN int lws_mqtt_bindata_cmp | ( | const lws_mqtt_str_t * | bd1, |
| const lws_mqtt_str_t * | bd2 ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN void lws_mqtt_str_init | ( | lws_mqtt_str_t * | s, |
| uint8_t * | buf, | ||
| uint16_t | lim, | ||
| char | nf ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN lws_mqtt_str_t * lws_mqtt_str_create | ( | uint16_t | lim | ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN lws_mqtt_str_t * lws_mqtt_str_create_init | ( | uint8_t * | buf, |
| uint16_t | len, | ||
| uint16_t | lim ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN lws_mqtt_str_t * lws_mqtt_str_create_cstr_dup | ( | const char * | buf, |
| uint16_t | lim ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN uint8_t * lws_mqtt_str_next | ( | lws_mqtt_str_t * | s, |
| uint16_t * | budget ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN int lws_mqtt_str_advance | ( | lws_mqtt_str_t * | s, |
| int | n ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN void lws_mqtt_str_free | ( | lws_mqtt_str_t ** | s | ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN int lws_mqtt_client_send_publish | ( | struct lws * | wsi, |
| lws_mqtt_publish_param_t * | pub, | ||
| const void * | buf, | ||
| uint32_t | len, | ||
| int | final ) |
lws_mqtt_client_send_publish() - lws_write a publish packet
| wsi | the mqtt child wsi |
| pub | additional information on what we're publishing |
| buf | payload to send, with LWS_PRE bytes valid before it as for lws_write() |
| len | length of data in buf |
| final | flag indicating this is the last part |
Issues part of, or the whole of, a PUBLISH frame. The first part of the frame contains the header, and uses the .qos and .payload_len parts of pub since MQTT requires the frame to specify the PUBLISH message length at the start. The len paramter may be less than pub.payload_len, in which case subsequent calls with more payload are needed to complete the frame.
Although the connection is stuck waiting for the remainder, in that it can't issue any other frames until the current one is completed, lws returns to the event loop normally and can continue the calls with additional payload even for huge frames as the data becomes available, consistent with timeout needs and latency to start any new frame (even, eg, related to ping / pong).
If you're sending large frames, the OS will typically not allow the data to be sent all at once to kernel side. So you should ideally cut the payload up into 1 or 2- mtu sized chunks and send that.
Final should be set when you're calling with the last part of the payload.
While a PUBLISH is going out in parts, nothing else can be sent on the connection, including the acks lws owes the broker for what it receives. lws holds a limited number of those, and when they fill up it stops reading the connection until it can write them, ie, until this PUBLISH is finished. So finishing a PUBLISH sent in parts must not wait for anything received on the same connection, or it may wait forever.
A QoS0 PUBLISH has no PUBACK, lws acknowledges it locally with LWS_CALLBACK_MQTT_ACK once the last part is sent. Like a real PUBACK for QoS1, that comes afterwards from the event loop, never from inside this call.
A stream has at most one operation awaiting the broker's ack: a QoS1 or QoS2 PUBLISH until its LWS_CALLBACK_MQTT_ACK (for QoS2, that comes at the PUBREC; lws completes the exchange itself), or a SUBSCRIBE or UNSUBSCRIBE until its SUBSCRIBED or UNSUBSCRIBED. Starting a QoS1 or QoS2 PUBLISH while one is awaiting its ack fails. After LWS_CALLBACK_MQTT_RESEND, the PUBLISH may be sent again with pub .dup set, which goes with the packet id it went with before, or the stream may go on to something else instead. Use more streams on the connection for more operations at once.
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN int lws_mqtt_client_send_subcribe | ( | struct lws * | wsi, |
| lws_mqtt_subscribe_param_t * | sub ) |
lws_mqtt_client_send_subcribe() - lws_write a subscribe packet
| wsi | the mqtt child wsi |
| sub | which topic(s) we want to subscribe to |
For topics other child streams have not already subscribed to, send a packet to the server asking to subscribe to them. If all topics listed are already subscribed to be the shared network connection, just trigger the LWS_CALLBACK_MQTT_SUBSCRIBED callback as if a SUBACK had come: like a real SUBACK, it comes afterwards from the event loop, not from inside this call.
It fails if the stream already has an operation awaiting the broker's ack, see lws_mqtt_client_send_publish().
sub doesn't need to exist after the return from this function.
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_mqtt_client_send_unsubcribe | ( | struct lws * | wsi, |
| const lws_mqtt_subscribe_param_t * | unsub ) |
lws_mqtt_client_send_unsubcribe() - lws_write a unsubscribe packet
| wsi | the mqtt child wsi |
| unsub | which topic(s) we want to unsubscribe from |
For topics other child streams are not subscribed to, send a packet to the server asking to unsubscribe from them. If all topics listed are already subscribed by other child streams on the shared network connection, just trigger the LWS_CALLBACK_MQTT_UNSUBSCRIBED callback as if a UNSUBACK had come: like a real UNSUBACK, it comes afterwards from the event loop, not from inside this call.
It fails if the stream already has an operation awaiting the broker's ack, see lws_mqtt_client_send_publish().
unsub doesn't need to exist after the return from this function.
References LWS_EXTERN, LWS_VISIBLE, and LWS_WARN_UNUSED_RESULT.
| LWS_VISIBLE LWS_EXTERN int lws_mqtt_client_qos2_rx_add | ( | struct lws * | wsi, |
| uint16_t | pkt_id ) |
lws_mqtt_client_qos2_rx_add() - inject a saved QoS2 packet ID into the rx list
| wsi | the mqtt child wsi |
| pkt_id | the packet ID to inject |
This allows the application to repopulate the unacknowledged QoS2 receives from persistent storage when a session is resumed.
References LWS_EXTERN, and LWS_VISIBLE.