1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00
libwebsockets/minimal-examples/ws-server/minimal-ws-server-threads-smp
Andy Green f7149e90c2 cc0: align dedication to CC0 FAQ recommended format
https://libwebsockets.org/pipermail/libwebsockets/2019-April/007937.html

thanks to Bruce Perens for noting it.

This doesn't change the intention or status of the CC0 files, they were
pure CC0 before (ie, public domain) and they are pure CC0 now.  It just
gets rid of the (C) part at the top of the dedication which may be read
to be a bit contradictory since the purpose is to make it public domain.
2019-05-02 09:29:01 +01:00
..
mount-origin minimal examples: ws-server-threads-smp 2019-01-28 07:02:33 +08:00
CMakeLists.txt minimal examples: ws-server-threads-smp 2019-01-28 07:02:33 +08:00
minimal-ws-server.c cc0: align dedication to CC0 FAQ recommended format 2019-05-02 09:29:01 +01:00
protocol_lws_minimal.c cc0: align dedication to CC0 FAQ recommended format 2019-05-02 09:29:01 +01:00
README.md minimal examples: ws-server-threads-smp 2019-01-28 07:02:33 +08:00

lws minimal ws server (threads) + SMP

This demonstrates both independent threads creating content as in the -threads example, and multiple service threads as in the http-server-smp example (but with ws).

build

You must first build libwebsockets itself with cmake -DLWS_MAX_SMP=8 or some other number greater than one.

 $ cmake . && make

Pthreads is required on your system.

usage

 $ ./lws-minimal-ws-server-threads-smp
[2019/01/28 06:59:17:4217] USER: LWS minimal ws server + threads + smp | visit http://localhost:7681
[2019/01/28 06:59:17:4219] NOTICE:   Service threads: 2
[2019/01/28 06:59:17:4220] NOTICE: LWS_CALLBACK_EVENT_WAIT_CANCELLED in svc tid 0x7fec48af8700
[2019/01/28 06:59:17:4220] NOTICE: LWS_CALLBACK_EVENT_WAIT_CANCELLED in svc tid 0x7fec48af8700
...

Visit http://localhost:7681 on multiple browser windows. You may need to open 4 before the second service thread is used (check "svc tid" in the browser output).

Two lws service threads are started.

Two separate asynchronous threads generate strings and add them to a ringbuffer, signalling all lws service threads to send new entries to all the browser windows.

This demonstrates how to safely manage asynchronously generated content and hook it up to the lws service threads.