[PATCH 1/2] mongoose: use websocket flag of connection struct

84 views
Skip to first unread message

michael....@weidmueller.com

unread,
Sep 20, 2023, 6:56:09 AM9/20/23
to swup...@googlegroups.com, Michael Bella
From: Michael Bella <michae...@weidmueller.com>

After the update of the mongoose webserver to version 7.8 new flags for
the connection struct were introduced. In the current version of
swupdate 'W' is set to the first position of the data array to mark
connections that use a websocket. For better readability the
is_websocket flag of the connection struct can be used.

Signed-off-by: Michael Bella <michae...@weidmueller.com>
---
mongoose/mongoose_interface.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
index 4b61acb..09d564e 100644
--- a/mongoose/mongoose_interface.c
+++ b/mongoose/mongoose_interface.c
@@ -363,7 +363,7 @@ static void broadcast_callback(struct mg_connection *nc, int ev,
if (ev == MG_EV_READ) {
struct mg_connection *t;
for (t = nc->mgr->conns; t != NULL; t = t->next) {
- if (t->data[0] != 'W') continue;
+ if (!t->is_websocket) continue;
mg_ws_send(t,(char *)nc->recv.buf, nc->recv.len, WEBSOCKET_OP_TEXT);
}
mg_iobuf_del(&nc->recv, 0, nc->recv.len);
@@ -671,7 +671,6 @@ static void websocket_handler(struct mg_connection *nc, void *ev_data)
{
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
mg_ws_upgrade(nc, hm, NULL);
- nc->data[0] = 'W';
}

static void ev_handler(struct mg_connection *nc, int ev, void *ev_data, void *fn_data)
--
2.30.2

michael....@weidmueller.com

unread,
Sep 20, 2023, 6:56:10 AM9/20/23
to swup...@googlegroups.com, Michael Bella
From: Michael Bella <michae...@weidmueller.com>

After the update of mongoose webserver to version 7.8 the heartbeat of
the websocket connection was removed. This patch adds a heartbeat that
sends a ping message every 20 seconds.

Signed-off-by: Michael Bella <michae...@weidmueller.com>
---
mongoose/mongoose_interface.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
index 09d564e..d343a5e 100644
--- a/mongoose/mongoose_interface.c
+++ b/mongoose/mongoose_interface.c
@@ -360,6 +360,7 @@ static void restart_handler(struct mg_connection *nc, void *ev_data)
static void broadcast_callback(struct mg_connection *nc, int ev,
void __attribute__ ((__unused__)) *ev_data, void __attribute__ ((__unused__)) *fn_data)
{
+ static uint64_t last_io_time = 0;
if (ev == MG_EV_READ) {
struct mg_connection *t;
for (t = nc->mgr->conns; t != NULL; t = t->next) {
@@ -367,6 +368,16 @@ static void broadcast_callback(struct mg_connection *nc, int ev,
mg_ws_send(t,(char *)nc->recv.buf, nc->recv.len, WEBSOCKET_OP_TEXT);
}
mg_iobuf_del(&nc->recv, 0, nc->recv.len);
+ last_io_time = mg_millis();
+ } else if (ev == MG_EV_POLL) {
+ struct mg_connection *t;
+ uint64_t now = *((uint64_t *)ev_data);
+ if (now < last_io_time + 20000) return;
+ for (t = nc->mgr->conns; t != NULL; t = t->next) {
+ if (!t->is_websocket) continue;
+ mg_ws_send(t, "", 0, WEBSOCKET_OP_PING);
+ }
+ last_io_time = now;
}
}

--
2.30.2

Michael Bella

unread,
Jan 29, 2024, 4:08:02 AM1/29/24
to swupdate
 I noticed that the patches are accepted in patchwork, but they are not present in the git repository. I there anything to do from my side to get the patches applied?

Stefano Babic

unread,
Jan 29, 2024, 5:22:50 AM1/29/24
to Michael Bella, swupdate
Hi Michael,

On 29.01.24 10:08, Michael Bella wrote:
>  I noticed that the patches are accepted in patchwork, but they are not
> present in the git repository. I there anything to do from my side to
> get the patches applied?
>

Yes - I never saw this patch, it looks like it silently landed in SPAM.

Can you check again your patches and post again the ones are missing ?
Thanks !

Best regards,
Stefano
> --
> You received this message because you are subscribed to the Google
> Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swupdate+u...@googlegroups.com
> <mailto:swupdate+u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/swupdate/8fa78c0c-5cd1-41ad-901e-c803afa2b364n%40googlegroups.com <https://groups.google.com/d/msgid/swupdate/8fa78c0c-5cd1-41ad-901e-c803afa2b364n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Message has been deleted

Stefano Babic

unread,
Jan 31, 2024, 5:40:51 AM1/31/24
to Michael Bella, swupdate
Reply all
Reply to author
Forward
0 new messages