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