multithreaded service
authorAndy Green <andy.green@linaro.org>
Mon, 18 Jan 2016 19:34:24 +0000 (03:34 +0800)
committerAndy Green <andy.green@linaro.org>
Tue, 19 Jan 2016 12:02:36 +0000 (20:02 +0800)
commitd3a550554241735dfa7a06b608a3908e845845fa
tree884ff0fe31f1acb10c825829a2eb70392cbaf6ff
parent3f63560876073484a3cbbf5eb2b3b35da0bfa677
multithreaded service

This adds support for multithreaded service to lws without adding any
threading or locking code in the library.

At context creation time you can request split the service part of the
context into n service domains, which are load-balanced so that the most
idle one gets the next listen socket accept.

There's a single listen socket on one port still.

User code may then spawn n threads doing n service loops / poll()s
simultaneously.  Locking is only required (I think) in the existing
FD lock callbacks already handled by the pthreads server example,
and that locking takes place in user code.  So the library remains
completely agnostic about the threading / locking scheme.

And by default, it's completely compatible with one service thread
so no changes are required by people uninterested in multithreaded
service.

However for people interested in extremely lightweight mass http[s]/
ws[s] service with minimum provisioning, the library can now do
everything out of the box.

To test it, just try

$ libwebsockets-test-server-pthreads -j 8

where -j controls the number of service threads

Signed-off-by: Andy Green <andy.green@linaro.org>
23 files changed:
CMakeLists.txt
README.build.md
README.coding.md
changelog
lib/client-handshake.c
lib/client-parser.c
lib/client.c
lib/context.c
lib/header.c
lib/libwebsockets.c
lib/libwebsockets.h
lib/lws-plat-unix.c
lib/lws-plat-win.c
lib/output.c
lib/parsers.c
lib/pollfd.c
lib/private-libwebsockets.h
lib/server-handshake.c
lib/server.c
lib/service.c
lib/ssl.c
lws_config.h.in
test-server/test-server-pthreads.c