1d4afb5ceSopenharmony_ci# lws minimal http server eventlib foreign
2d4afb5ceSopenharmony_ci
3d4afb5ceSopenharmony_ciCommandline option|Meaning
4d4afb5ceSopenharmony_ci---|---
5d4afb5ceSopenharmony_ci-d <loglevel>|Debug verbosity in decimal, eg, -d15
6d4afb5ceSopenharmony_ci--uv|Use the libuv event library (lws must have been configured with `-DLWS_WITH_LIBUV=1`)
7d4afb5ceSopenharmony_ci--event|Use the libevent library (lws must have been configured with `-DLWS_WITH_LIBEVENT=1`)
8d4afb5ceSopenharmony_ci--ev|Use the libev event library (lws must have been configured with `-DLWS_WITH_LIBEV=1`)
9d4afb5ceSopenharmony_ci--sd|Use the systemd event library (lws must have been configured with `-DLWS_WITH_SDEVENT=1`)
10d4afb5ceSopenharmony_ci
11d4afb5ceSopenharmony_ciNotice libevent and libev cannot coexist in the one library.  But all the other combinations are OK.
12d4afb5ceSopenharmony_ci
13d4afb5ceSopenharmony_cix|libuv|libevent|libev
14d4afb5ceSopenharmony_ci---|---|---|---
15d4afb5ceSopenharmony_cilibuv|-|OK|OK
16d4afb5ceSopenharmony_cilibevent|OK|-|no
17d4afb5ceSopenharmony_cilibev|OK|no|-
18d4afb5ceSopenharmony_ci
19d4afb5ceSopenharmony_ciThis demonstrates having lws take part in a libuv loop owned by
20d4afb5ceSopenharmony_cisomething else, with its own objects running in the loop.
21d4afb5ceSopenharmony_ci
22d4afb5ceSopenharmony_ciLws can join the loop, and clean up perfectly after itself without
23d4afb5ceSopenharmony_cileaving anything behind or making trouble in the larger loop, which
24d4afb5ceSopenharmony_cidoes not need to stop during lws creation or destruction.
25d4afb5ceSopenharmony_ci
26d4afb5ceSopenharmony_ciFirst the foreign loop is created with a 1s timer, and runs alone for 5s.
27d4afb5ceSopenharmony_ci
28d4afb5ceSopenharmony_ciThen the lws context is created inside the timer callback and runs for 10s...
29d4afb5ceSopenharmony_ciduring this period you can visit http://localhost:7681 for normal lws
30d4afb5ceSopenharmony_ciservice using the foreign loop.
31d4afb5ceSopenharmony_ci
32d4afb5ceSopenharmony_ciAfter the 10s are up, the lws context is destroyed inside the foreign loop
33d4afb5ceSopenharmony_citimer.  The foreign loop runs alone again for a further 5s and then
34d4afb5ceSopenharmony_ciexits itself.
35d4afb5ceSopenharmony_ci
36d4afb5ceSopenharmony_ci## build
37d4afb5ceSopenharmony_ci
38d4afb5ceSopenharmony_ci```
39d4afb5ceSopenharmony_ci $ cmake . && make
40d4afb5ceSopenharmony_ci```
41d4afb5ceSopenharmony_ci
42d4afb5ceSopenharmony_ci## usage
43d4afb5ceSopenharmony_ci
44d4afb5ceSopenharmony_ci```
45d4afb5ceSopenharmony_ci $ ./lws-minimal-http-server-eventlib-foreign
46d4afb5ceSopenharmony_ci[2018/03/29 12:19:31:3480] USER: LWS minimal http server eventlib + foreign loop | visit http://localhost:7681
47d4afb5ceSopenharmony_ci[2018/03/29 12:19:31:3724] NOTICE: Creating Vhost 'default' port 7681, 1 protocols, IPv6 off
48d4afb5ceSopenharmony_ci[2018/03/29 12:19:31:3804] NOTICE:  Using foreign event loop...
49d4afb5ceSopenharmony_ci[2018/03/29 12:19:31:3938] USER: Foreign 1Hz timer
50d4afb5ceSopenharmony_ci[2018/03/29 12:19:32:4011] USER: Foreign 1Hz timer
51d4afb5ceSopenharmony_ci[2018/03/29 12:19:33:4024] USER: Foreign 1Hz timer
52d4afb5ceSopenharmony_ci^C[2018/03/29 12:19:33:8868] NOTICE: Signal 2 caught, exiting...
53d4afb5ceSopenharmony_ci[2018/03/29 12:19:33:8963] USER: main: starting exit cleanup...
54d4afb5ceSopenharmony_ci[2018/03/29 12:19:33:9064] USER: main: lws context destroyed: cleaning the foreign loop
55d4afb5ceSopenharmony_ci[2018/03/29 12:19:33:9108] USER: main: exiting...
56d4afb5ceSopenharmony_ci```
57d4afb5ceSopenharmony_ci
58d4afb5ceSopenharmony_ciVisit http://localhost:7681
59d4afb5ceSopenharmony_ci
60