1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-30 00:00:16 +01:00
libwebsockets/lib/plat/unix
Andy Green 1a93e73402 fakewsi: replace with smaller substructure
Currently we always reserve a fakewsi per pt so events that don't have a related actual
wsi, like vhost-protocol-init or vhost cert init via protocol callback can make callbacks
that look reasonable to user protocol handler code expecting a valid wsi every time.

This patch splits out stuff that user callbacks often unconditionally expect to be in
a wsi, like context pointer, vhost pointer etc into a substructure, which is composed
into struct lws at the top of it.  Internal references (struct lws is opaque, so there
are only internal references) are all updated to go via the substructre, the compiler
should make that a NOP.

Helpers are added when fakewsi is used and referenced.

If not PLAT_FREERTOS, we continue to provide a full fakewsi in the pt as before,
although the helpers improve consistency by zeroing down the substructure.  There is
a huge amount of user code out there over the last 10 years that did not always have
the minimal examples to follow, some of it does some unexpected things.

If it is PLAT_FREERTOS, that is a newer thing in lws and users have the benefit of
being able to follow the minimal examples' approach.  For PLAT_FREERTOS we don't
reserve the fakewsi in the pt any more, saving around 800 bytes.  The helpers then
create a struct lws_a (the substructure) on the stack, zero it down (but it is only
like 4 pointers) and prepare it with whatever we know like the context.

Then we cast it to a struct lws * and use it in the user protocol handler call.
In this case, the remainder of the struct lws is undefined.  However the amount of
old protocol handlers that might touch things outside of the substructure in
PLAT_FREERTOS is very limited compared to legacy lws user code and the saving is
significant on constrained devices.

User handlers should not be touching everything in a wsi every time anyway, there
are several cases where there is no valid wsi to do the call with.  Dereference of
things outside the substructure should only happen when the callback reason shows
there is a valid wsi bound to the activity (as in all the minimal examples).
2020-07-20 06:28:52 +01:00
..
android cleaning 2020-01-05 22:17:58 +00:00
CMakeLists.txt cmakelists: clean out pthreads and normalize libmount args 2020-06-03 17:14:03 +01:00
private-lib-plat-unix.h lws_mutex 2020-06-16 19:45:35 +01:00
unix-caps.c _GNU_SOURCE: only define if not already defined 2019-12-22 18:17:45 +00:00
unix-fds.c CTest: migrate and deprecate existing selftest scripts 2020-05-11 15:40:13 +01:00
unix-file.c _GNU_SOURCE: only define if not already defined 2019-12-22 18:17:45 +00:00
unix-init.c sul: multiple timer domains 2020-06-02 08:37:10 +01:00
unix-misc.c esp32-wrover-kit 2020-06-30 19:35:41 +01:00
unix-pipe.c fakewsi: replace with smaller substructure 2020-07-20 06:28:52 +01:00
unix-plugins.c coverity: fixes plugin error path leak and logging method sign check 2020-01-14 08:23:25 +00:00
unix-resolv.c ntpclient: add plat-specific init with env var LWS_NTP_SERVER able to set it on unix and windows 2020-04-25 15:11:21 +01:00
unix-service.c fakewsi: replace with smaller substructure 2020-07-20 06:28:52 +01:00
unix-sockets.c iOS: detect and avoid net/route.h 2020-04-23 06:30:11 +01:00
unix-spawn.c fakewsi: replace with smaller substructure 2020-07-20 06:28:52 +01:00