Sun, 05 May 2024 17:24:54 +0200
Much faster shutdown of the websocket service.
--- a/thermferm/thermferm.c Sun May 05 16:31:47 2024 +0200 +++ b/thermferm/thermferm.c Sun May 05 17:24:54 2024 +0200 @@ -2061,7 +2061,7 @@ while (my_devices_state) { mDelay(50); }; my_one_wire_shutdown = 1; while (my_one_wire_state) { mDelay(50); }; - my_ws_shutdown = 1; + my_ws_stop(); while (my_ws_state) { mDelay(50); }; mqtt_disconnect();
--- a/thermferm/websocket.c Sun May 05 16:31:47 2024 +0200 +++ b/thermferm/websocket.c Sun May 05 17:24:54 2024 +0200 @@ -309,7 +309,6 @@ } case LWS_CALLBACK_PROTOCOL_DESTROY: - syslog(LOG_NOTICE, "Websocket: protocol cleaning up"); for (n = 0; n < sizeof ringbuffer / sizeof ringbuffer[0]; n++) if (ringbuffer[n].payload) free(ringbuffer[n].payload); @@ -441,6 +440,15 @@ } +/* + * Fast way to stop the websocket service. + */ +void my_ws_stop(void) +{ + my_ws_shutdown = 1; + lws_cancel_service(context); +} + void *my_ws_loop(void *threadid) { @@ -464,7 +472,7 @@ my_ws_state = 0; return (void *)1; } - syslog(LOG_NOTICE, "Websocket: server started port %d, pid=%d", info.port, pid); + syslog(LOG_NOTICE, "Thread my_ws_loop started port %d, pid=%d", info.port, pid); /* * Loop forever until external shutdown variable is set. @@ -476,7 +484,7 @@ lws_context_destroy(context); my_ws_state = 0; - syslog(LOG_NOTICE, "Websocket: server stopped"); + syslog(LOG_NOTICE, "Thread my_ws_loop stopped"); return (void *)0; }
--- a/thermferm/websocket.h Sun May 05 16:31:47 2024 +0200 +++ b/thermferm/websocket.h Sun May 05 17:24:54 2024 +0200 @@ -24,6 +24,11 @@ void ws_check(void); /** + * @brief Stop websocket thread by setting the shutdown flag and sending a cancel service. + */ +void my_ws_stop(void); + +/** * @brief The websockets server thread. */ void *my_ws_loop(void *);