1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-23 00:00:06 +01:00
libwebsockets/lib/system
Andy Green b3131fdfdd cmakelist: Augean Stables refactor
Establish a new distributed CMake architecture with CMake code related to
a source directory moving to be in the subdir in its own CMakeLists.txt.
In particular, there's now one in ./lib which calls through to ones
further down the directory tree like ./lib/plat/xxx, ./lib/roles/xxx etc.

This cuts the main CMakelists.txt from 98KB -> 33KB, about a 66% reduction,
and it's much easier to maintain sub-CMakeLists.txt that are in the same
directory as the sources they manage, and conceal all the details that that
level.

Child CMakelists.txt become responsible for:

 - include_directories() definition (this is not supported by CMake
   directly, it passes it back up via PARENT_SCOPE vars in helper
   macros)

 - Addition child CMakeLists.txt inclusion, for example toplevel ->
   role -> role subdir

 - Source file addition to the build

 - Dependent library path resolution... this is now a private thing
   in the child CMakeLists.txt, it just passes back any adaptations
   to include_directories() and the LIB_LIST without filling the
   parent namespace with the details
2020-05-27 08:40:12 +01:00
..
async-dns ctest: fixes-and-changes 2020-04-19 08:43:01 +01:00
dhcpclient dhcpclient: Fix unused-variable error in release 2020-04-23 20:03:31 +01:00
ntpclient 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
CMakeLists.txt cmakelist: Augean Stables refactor 2020-05-27 08:40:12 +01:00
README.md lws_system: helpers for attaching to existing event loop from other threads 2020-01-05 22:17:58 +00:00
system.c client: secure streams 2020-03-04 12:17:49 +00:00

LWS System Helpers

Lws now has a little collection of helper utilities for common network-based functions necessary for normal device operation, eg, async DNS, ntpclient (necessary for tls validation), and DHCP client.

Conventions

If any system helper is enabled for build, lws creates an additional vhost "system" at Context Creation time. Wsi that are created for the system features are bound to this. In the context object, this is available as .vhost_system.

Attaching to an existing context from other threads

To simplify the case different pieces of code want to attach to a single lws_context at runtime, from different thread contexts, lws_system has an api via an lws_system operation function pointer where the other threads can use platform-specific locking to request callbacks to their own code from the lws event loop thread context safely.

For convenience, the callback can be delayed until the system has entered or passed a specified system state, eg, LWS_SYSTATE_OPERATIONAL so the code will only get called back after the network, ntpclient and auth have been done. Additionally an opaque pointer can be passed to the callback when it is called from the lws event loop context.

Implementing the system-specific locking

lws_system_ops_t struct has a member .attach

	int (*attach)(struct lws_context *context, int tsi, lws_attach_cb_t *cb,
		      lws_system_states_t state, void *opaque,
		      struct lws_attach_item **get);

This should be defined in user code as setting locking, then passing the arguments through to a non-threadsafe helper

int
__lws_system_attach(struct lws_context *context, int tsi, lws_attach_cb_t *cb,
		    lws_system_states_t state, void *opaque,
		    struct lws_attach_item **get);

that does the actual attach work. When it returns, the locking should be unlocked and the return passed back.

Attaching the callback request

User code should call the lws_system_ops_t .attach function like

	lws_system_get_ops(context)->attach(...);

The callback function which will be called from the lws event loop context should look like this

void my_callback(struct lws_context *context, int tsi, void *opaque);

with the callback function name passed into the (*attach)() call above. When the callback happens, the opaque user pointer set at the (*attach)() call is passed back to it as an argument.