From 14379d1917291723037aa57c0d4c2a02768ad01d Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 5 Nov 2024 07:41:11 +0000 Subject: [PATCH 1/4] mqtt: fix MQTT client PINGREQ failure when using LIBUV as event driver. --- lib/roles/mqtt/ops-mqtt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/roles/mqtt/ops-mqtt.c b/lib/roles/mqtt/ops-mqtt.c index ceac2f578..db53f7ed8 100644 --- a/lib/roles/mqtt/ops-mqtt.c +++ b/lib/roles/mqtt/ops-mqtt.c @@ -440,6 +440,11 @@ rops_issue_keepalive_mqtt(struct lws *wsi, int isvalid) } nwsi->mqtt->send_pingreq = 1; + +#if defined (LWS_WITH_LIBUV) + nwsi->mux_substream = 0; +#endif + lws_callback_on_writable(nwsi); return 0; @@ -562,6 +567,11 @@ rops_close_kill_connection_mqtt(struct lws *wsi, enum lws_close_status reason) lws_wsi_tag(wsi), lws_wsi_tag(wsi->mux.parent_wsi), wsi->mux.child_list); //lws_wsi_mux_dump_children(wsi); +#if defined(LWS_WITH_LIBUV) + struct lws *nwsi = lws_get_network_wsi(wsi); + if (nwsi->mux_substream == 0) + nwsi->mux_substream = 1; +#endif if (wsi->mux_substream #if defined(LWS_WITH_CLIENT) From a08ffcbf3e4c4e9c233d1f2eac62e8c819d0dc39 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 12 Nov 2024 13:35:09 +0000 Subject: [PATCH 2/4] mqtt: change the event loop test to runtime --- lib/roles/mqtt/ops-mqtt.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/roles/mqtt/ops-mqtt.c b/lib/roles/mqtt/ops-mqtt.c index db53f7ed8..eaacf56f6 100644 --- a/lib/roles/mqtt/ops-mqtt.c +++ b/lib/roles/mqtt/ops-mqtt.c @@ -441,9 +441,9 @@ rops_issue_keepalive_mqtt(struct lws *wsi, int isvalid) nwsi->mqtt->send_pingreq = 1; -#if defined (LWS_WITH_LIBUV) - nwsi->mux_substream = 0; -#endif + if (lws_check_opt(wsi->a.context->options, LWS_SERVER_OPTION_LIBUV)) { + nwsi->mux_substream = 0; + } lws_callback_on_writable(nwsi); @@ -567,11 +567,11 @@ rops_close_kill_connection_mqtt(struct lws *wsi, enum lws_close_status reason) lws_wsi_tag(wsi), lws_wsi_tag(wsi->mux.parent_wsi), wsi->mux.child_list); //lws_wsi_mux_dump_children(wsi); -#if defined(LWS_WITH_LIBUV) - struct lws *nwsi = lws_get_network_wsi(wsi); - if (nwsi->mux_substream == 0) - nwsi->mux_substream = 1; -#endif + if (lws_check_opt(wsi->a.context->options, LWS_SERVER_OPTION_LIBUV)) { + struct lws *nwsi = lws_get_network_wsi(wsi); + if (nwsi->mux_substream == 0) + nwsi->mux_substream = 1; + } if (wsi->mux_substream #if defined(LWS_WITH_CLIENT) From 15dec8ef9098bf2935e1d718d172d5027028efb5 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 21 Nov 2024 08:48:05 +0000 Subject: [PATCH 3/4] mqtt: fix issue that unsubscribe wildcard topic assert failed --- lib/roles/mqtt/mqtt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/roles/mqtt/mqtt.c b/lib/roles/mqtt/mqtt.c index aaac84b8b..7ae7e677d 100644 --- a/lib/roles/mqtt/mqtt.c +++ b/lib/roles/mqtt/mqtt.c @@ -2325,7 +2325,7 @@ lws_mqtt_client_send_unsubcribe(struct lws *wsi, for (n = 0; n < unsub->num_topics; n++) { mysub = lws_mqtt_find_sub(nwsi->mqtt, unsub->topic[n].name); - assert(mysub); + //assert(mysub); if (mysub && --mysub->ref_count == 0) { lwsl_notice("%s: Need to send UNSUB\n", __func__); From 28f09fe4fbc3b3debfb60d669d8793fe1a3ea8d8 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sun, 24 Nov 2024 13:02:49 +0000 Subject: [PATCH 4/4] mqtt: fix issue about mux_substream of child wsi --- lib/roles/mqtt/ops-mqtt.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/roles/mqtt/ops-mqtt.c b/lib/roles/mqtt/ops-mqtt.c index eaacf56f6..4077b7258 100644 --- a/lib/roles/mqtt/ops-mqtt.c +++ b/lib/roles/mqtt/ops-mqtt.c @@ -440,11 +440,6 @@ rops_issue_keepalive_mqtt(struct lws *wsi, int isvalid) } nwsi->mqtt->send_pingreq = 1; - - if (lws_check_opt(wsi->a.context->options, LWS_SERVER_OPTION_LIBUV)) { - nwsi->mux_substream = 0; - } - lws_callback_on_writable(nwsi); return 0; @@ -557,6 +552,16 @@ rops_callback_on_writable_mqtt(struct lws *wsi) ) return 1; + if (lws_check_opt(wsi->a.context->options, LWS_SERVER_OPTION_LIBUV)) { + if (network_wsi->mux_substream != 0) + network_wsi->mux_substream = 0; + + lws_start_foreach_ll(struct lws *, w, network_wsi->mux.child_list) { + if (w->mux.requested_POLLOUT == 0) + w->mux.requested_POLLOUT = 1; + } lws_end_foreach_ll(w, mux.sibling_list); + } + return 0; }