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 d3308df40f windows: pthreads
Add support for external pthreads lib on windows and some docs about how to do.

It can build with LWS_WITH_THREADPOOL and LWS_WITH_MINIMAL_EXAMPLES including the
pthreads-dependent ones without warnings or errors on windows platform as well with this.

pthreads_t can be anything, including a struct - not a pointer-to-a-struct
but the struct itself.  These can't be cast to a void * for printing as they can
on linux, where the base type is a pointer.

Let's fix all the usage of those to determine their own thread index in terms
of the meaning to the program rather than as a tid.
2020-04-07 14:05:21 +01:00
..
mount-origin lws logo: update minimal examples 2020-03-06 04:46:39 +00:00
CMakeLists.txt windows: pthreads 2020-04-07 14:05:21 +01:00
minimal-ws-server.c windows: pthreads 2020-04-07 14:05:21 +01:00
protocol_lws_minimal.c windows: pthreads 2020-04-07 14:05:21 +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.