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 d98101d1e3 plugins: generalize and provide public api
Move the common plugin scanning dir stuff to be based on lws_dir, which
already builds for windows.  Previously this was done via dirent for unix
and libuv for windows.

Reduce the dl plat stuff to just wrap instantiation and destruction of
dynlibs, establish common code in lib/misc/dir.c for plugin scanning
itself.

Migrate the libuv windows dl stuff to windows-plugins.c, so that he's
available even if later libuv loop support becomes and event lib plugin.

Remove the existing api exports scheme for plugins, just export a const struct
now which has a fixed header type but then whatever you want afterwards depending
on the class / purpose of the plugin.  Place a "class" string in the header so
there can be different kinds of plugins implying different types exported.

Make the plugin apis public and add support for filter by class string, and
per instantation / destruction callbacks so the subclassed header type can
do its thing for the plugin class.  The user provides a linked-list base
for his class of plugins, so he can manage them completely separately and
in user code / user export types.

Rip out some last hangers-on from generic sessions / tables.

This is all aimed at making the plugins support general enough so it can
provide event lib plugins later.
2020-08-31 16:51:37 +01:00
..
mount-origin lws logo: update minimal examples 2020-03-06 04:46:39 +00:00
CMakeLists.txt cmake: mark all the subprojects as explicitly C 2020-08-31 16:51:36 +01:00
minimal-ws-server.c windows: pthreads 2020-04-07 14:05:21 +01:00
protocol_lws_minimal.c plugins: generalize and provide public api 2020-08-31 16:51:37 +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.