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 c9731c5f17 type comparisons: fixes
This is a huge patch that should be a global NOP.

For unix type platforms it enables -Wconversion to issue warnings (-> error)
for all automatic casts that seem less than ideal but are normally concealed
by the toolchain.

This is things like passing an int to a size_t argument.  Once enabled, I
went through all args on my default build (which build most things) and
tried to make the removed default cast explicit.

With that approach it neither change nor bloat the code, since it compiles
to whatever it was doing before, just with the casts made explicit... in a
few cases I changed some length args from int to size_t but largely left
the causes alone.

From now on, new code that is relying on less than ideal casting
will complain and nudge me to improve it by warnings.
2021-01-05 10:56:38 +00:00
..
mount-origin lws logo: update minimal examples 2020-03-06 04:46:39 +00:00
CMakeLists.txt cmake: latest cmake shows dep warnings for scripts < 2.8.12 2020-12-06 19:44:54 +00:00
minimal-ws-server.c windows: pthreads 2020-04-07 14:05:21 +01:00
protocol_lws_minimal.c type comparisons: fixes 2021-01-05 10:56:38 +00: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.