Andy Green | e052edb | 2018-03-29 11:45:43 +0800 | [diff] [blame] | 1 | # lws minimal http server libuv foreign |
| 2 | |
| 3 | This demonstrates having lws take part in a libuv loop owned by |
| 4 | something else, with its own objects running in the loop. |
| 5 | |
Andy Green | d37b383 | 2018-04-29 10:44:36 +0800 | [diff] [blame^] | 6 | Lws can join the loop, and clean up perfectly after itself without |
| 7 | leaving anything behind or making trouble in the larger loop, which |
| 8 | does not need to stop during lws creation or destruction. |
| 9 | |
| 10 | First the foreign loop is created with a 1s timer, and runs alone for 5s. |
| 11 | |
| 12 | Then the lws context is created inside the timer callback and runs for 10s... |
| 13 | during this period you can visit http://localhost:7681 for normal lws |
| 14 | service using the foreign loop. |
| 15 | |
| 16 | After the 10s are up, the lws context is destroyed inside the foreign loop |
| 17 | timer. The foreign loop runs alone again for a further 5s and then |
| 18 | exits itself. |
Andy Green | e052edb | 2018-03-29 11:45:43 +0800 | [diff] [blame] | 19 | |
| 20 | ## build |
| 21 | |
| 22 | ``` |
| 23 | $ cmake . && make |
| 24 | ``` |
| 25 | |
| 26 | ## usage |
| 27 | |
| 28 | ``` |
| 29 | $ ./lws-minimal-http-server-libuv-foreign |
| 30 | [2018/03/29 12:19:31:3480] USER: LWS minimal http server libuv + foreign loop | visit http://localhost:7681 |
| 31 | [2018/03/29 12:19:31:3724] NOTICE: Creating Vhost 'default' port 7681, 1 protocols, IPv6 off |
| 32 | [2018/03/29 12:19:31:3804] NOTICE: Using foreign event loop... |
| 33 | [2018/03/29 12:19:31:3938] USER: Foreign 1Hz timer |
| 34 | [2018/03/29 12:19:32:4011] USER: Foreign 1Hz timer |
| 35 | [2018/03/29 12:19:33:4024] USER: Foreign 1Hz timer |
| 36 | ^C[2018/03/29 12:19:33:8868] NOTICE: Signal 2 caught, exiting... |
| 37 | [2018/03/29 12:19:33:8963] USER: main: starting exit cleanup... |
| 38 | [2018/03/29 12:19:33:9064] USER: main: lws context destroyed: cleaning the foreign loop |
| 39 | [2018/03/29 12:19:33:9108] USER: main: exiting... |
| 40 | ``` |
| 41 | |
| 42 | Visit http://localhost:7681 |
| 43 | |