1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00
Commit graph

296 commits

Author SHA1 Message Date
Andy Green
1d05f429dc lws_plugins 2020-08-31 16:51:37 +01:00
Andy Green
c6c7ab2b44 event libs: default to building as dynamically loaded plugins
Event lib support as it has been isn't scaling well, at the low level
libevent and libev headers have a namespace conflict so they can't
both be built into the same image, and at the distro level, binding
all the event libs to libwebsockets.so makes a bloaty situation for
packaging, lws will drag in all the event libs every time.

This patch implements the plan discussed here

https://github.com/warmcat/libwebsockets/issues/1980

and refactors the event lib support so they are built into isolated
plugins and bound at runtime according to what the application says
it wants to use.  The event lib plugins can be packaged individually
so that only the needed sets of support are installed (perhaps none
of them if the user code is OK with the default poll() loop).  And
dependent user code can mark the specific event loop plugin package
as required so pieces are added as needed.

The eventlib-foreign example is also refactored to build the selected
lib support isolated.

A readme is added detailing the changes and how to use them.

https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.event-libs.md
2020-08-31 16:51:37 +01:00
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
21stcaveman
8ca839dfb0 Subject: plugins: lwsws will not iterate all plugin directories
Apply the same logic to both libuv and the generic unix plugin implementations
2020-08-31 16:51:37 +01:00
Andy Green
c21467a8f0 coverity: 50976: check fsync return for cert write 2020-08-19 07:23:19 +01:00
Andy Green
e2dcbdc81a coverity: 49785: confirm initgroups worked 2020-08-19 07:21:55 +01:00
Andy Green
a6b4bd8bfc coverity: 62374: no need to init n 2020-08-18 14:00:54 +01:00
William Yu
98f63c6c8d freertos: explicitly include semphr.h
Although it's already included in lws esp-idf freertos case, in some
other freertos environments it's necessary to explicitly include
the semaphore header.
2020-08-12 05:54:27 +01:00
Andy Green
2edd83dac1 freebsd: sai build adaptations 2020-08-10 15:04:10 +01:00
Mike Owens
e3b34d3e08 Subject: Fixes to build on FreeBSD and Illumos 2020-08-10 15:04:10 +01:00
Andy Green
924bd78085 clean: reduce log verbosity in various places 2020-08-10 15:04:10 +01:00
Andy Green
140c1ede53 eventfd: use eventfd_read to check existence since its what we use 2020-07-29 20:36:19 +01:00
Andy Green
ddcbb6fa80 lws_interface_to_sa: confirm getifaddrs worked
We don't actually check that it provided results... return diags and
that the interface is usable if it didn't.

Also explicitly check ifa_name for being NULL, since it seems some
platforms can do that even with an ifa_addr (thanks to Jed)
2020-07-29 11:14:37 +01:00
Andy Green
9e6cefcfad lws_netdev: fix rssi averaging 2020-07-21 08:16:01 +01:00
Andy Green
1a93e73402 fakewsi: replace with smaller substructure
Currently we always reserve a fakewsi per pt so events that don't have a related actual
wsi, like vhost-protocol-init or vhost cert init via protocol callback can make callbacks
that look reasonable to user protocol handler code expecting a valid wsi every time.

This patch splits out stuff that user callbacks often unconditionally expect to be in
a wsi, like context pointer, vhost pointer etc into a substructure, which is composed
into struct lws at the top of it.  Internal references (struct lws is opaque, so there
are only internal references) are all updated to go via the substructre, the compiler
should make that a NOP.

Helpers are added when fakewsi is used and referenced.

If not PLAT_FREERTOS, we continue to provide a full fakewsi in the pt as before,
although the helpers improve consistency by zeroing down the substructure.  There is
a huge amount of user code out there over the last 10 years that did not always have
the minimal examples to follow, some of it does some unexpected things.

If it is PLAT_FREERTOS, that is a newer thing in lws and users have the benefit of
being able to follow the minimal examples' approach.  For PLAT_FREERTOS we don't
reserve the fakewsi in the pt any more, saving around 800 bytes.  The helpers then
create a struct lws_a (the substructure) on the stack, zero it down (but it is only
like 4 pointers) and prepare it with whatever we know like the context.

Then we cast it to a struct lws * and use it in the user protocol handler call.
In this case, the remainder of the struct lws is undefined.  However the amount of
old protocol handlers that might touch things outside of the substructure in
PLAT_FREERTOS is very limited compared to legacy lws user code and the saving is
significant on constrained devices.

User handlers should not be touching everything in a wsi every time anyway, there
are several cases where there is no valid wsi to do the call with.  Dereference of
things outside the substructure should only happen when the callback reason shows
there is a valid wsi bound to the activity (as in all the minimal examples).
2020-07-20 06:28:52 +01:00
Andy Green
a59035d821 spawn: only apply deathsig on child 2020-07-17 13:52:13 +01:00
Andy Green
1c3b7a2653 cgi: also use explicit env setting for OSX
...if no execvpe...
2020-07-17 13:49:14 +01:00
Andy Green
6762c7367f remove: old esp32 helper pieces
The old esp32 -factory stuff along with the lws support doesn't have a
future in its old form.  It has users but the ratio of effort to
contribution is really especially bad.  I haven't updated it for more
than a year since esp-idf changes broke the original stuff.

Freertos plat is alive and well and getting a lot of new use, ESP-32 is
supported both there and by modern lws_drivers pieces, including in CI
on real hardware, any further effort will be invested in that direction
instead of more vendor api-specific code (outside of wrapper
implementation).

lws_drivers wraps any SDK apis in generic lws apis such that your code
just uses those, enabling it to become SDK / SoC / vendor independent.
Its first implementation is on esp-idf, the low and mid-level features
that were in the old -factory are already available using that and
new technologies like lws_struct and Secure Streams.
2020-07-15 16:18:00 +01:00
Andy Green
4939b87e66 lws_netdev: use lws_settings
Perform the AP selection using lws_settings and a generic scan state machine
2020-07-07 15:23:19 +01:00
Andy Green
b72ab32c17 lws_netdev 2020-07-02 10:36:31 +01:00
Andy Green
65545d2d21 lws-settings 2020-07-02 10:20:17 +01:00
Andy Green
63c1e8ba00 esp32-wrover-kit
Add lws_display and minimal example support for esp32-wrover to match wsp32-heltec-wb32

Since no usable buttons that don't affect something else on wrover kit, assumes
a button to 0V on GPIO14.
2020-06-30 19:35:41 +01:00
Andy Green
8eca7e17f2 lws_smd: system message distribution
- Add low level system message distibution framework
 - Add support for local Secure Streams to participate using _lws_smd streamtype
 - Add apit test and minimal example
 - Add SS proxy support for _lws_smd

See minimal-secure-streams-smd README.md
2020-06-27 07:57:22 +01:00
Andy Green
ceb4e53174 lws_button: classification
Now there's an abstract button class regardless of the underlying
connection, we can add more sophicsticated analysis on top of it
for processing its usually noisy events and classifying them into
smd-ready click, long-click or double-click events.

A "regime" defines the timing limits for different press recognition
and can be specified per-button, if not given a default regime is
applied.
2020-06-27 07:57:22 +01:00
Andy Green
33f1003305 lws_pwm 2020-06-27 07:57:22 +01:00
Andy Green
fdf8a5f931 lws_mutex
Add a simple platform wrapper around OS mutexes.
*nix and windows == pthreads
freertos = SemaphoreHandle
2020-06-16 19:45:35 +01:00
Andy Green
15ce46d971 drivers: initial generic gpio and i2c plus bitbang
Make a start on generic peripheral and bus drivers to provide
meta-functionality regardless of platform.

On the one hand this simply provides...

 - bitbang i2c on top of esp-idf gpio apis
 - ssd1306 oled chip driver as found on Heltec WB32
 - modifications to the minimal example test for esp32 to use that

... on the other hand, those capabilities are provided by creating:

 - an abstract i2c class object
 - an abstract gpio class object
 - i2c class implementation using the abstract gpio for bitbang
 - an abstract display class object
 - an abstract display state (brightness, animated change,
    on/off/init tracking, autodim after inactive, auto-off /
    blanking after inactive)

... with the intention, eg, you only have to add a platform
implementation for the gpio to be able to use the i2c-based
display drivers and state handling, and i2c bitbang, without
any other modifications.
2020-06-10 19:17:08 +01:00
Andy Green
e9b3898c99 spawn: retry when last stdwsi close may not be immediately followed by reapable process 2020-06-04 10:12:08 +01:00
Andy Green
425da070e3 cmakelists: clean out pthreads and normalize libmount args 2020-06-03 17:14:03 +01:00
Andy Green
286cf4357a sul: multiple timer domains
Adapt the pt sul owner list to be an array, and define two different lists,
one that acts like before and is the default for existing users, and another
that has the ability to cooperate with systemwide suspend to restrict the
interval spent suspended so that it will wake in time for the earliest
thing on this wake-suspend sul list.

Clean the api a bit and add lws_sul_cancel() that only needs the sul as the
argument.

Add a flag for client creation info to indicate that this client connection
is important enough that, eg, validity checking it to detect silently dead
connections should go on the wake-suspend sul list.  That flag is exposed in
secure streams policy so it can be added to a streamtype with
"swake_validity": true

Deprecate out the old vhost timer stuff that predates sul.  Add a flag
LWS_WITH_DEPRECATED_THINGS in cmake so users can get it back temporarily
before it will be removed in a v4.2.

Adapt all remaining in-tree users of it to use explicit suls.
2020-06-02 08:37:10 +01:00
Andy Green
911898ad70 windows: recent win10 support Unix Domain
Allow selection of Unix Domain Sockets on windows since it is supported
for the last couple of years on windows 10

https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/

... if only they could add a full set of posix pieces to go with it
(and abstract namespace UDS which doesn't work apparently) so that
the parts dealing with uid / gid don't have to be disabled.
2020-06-02 08:37:10 +01:00
Andy Green
b3131fdfdd cmakelist: Augean Stables refactor
Establish a new distributed CMake architecture with CMake code related to
a source directory moving to be in the subdir in its own CMakeLists.txt.
In particular, there's now one in ./lib which calls through to ones
further down the directory tree like ./lib/plat/xxx, ./lib/roles/xxx etc.

This cuts the main CMakelists.txt from 98KB -> 33KB, about a 66% reduction,
and it's much easier to maintain sub-CMakeLists.txt that are in the same
directory as the sources they manage, and conceal all the details that that
level.

Child CMakelists.txt become responsible for:

 - include_directories() definition (this is not supported by CMake
   directly, it passes it back up via PARENT_SCOPE vars in helper
   macros)

 - Addition child CMakeLists.txt inclusion, for example toplevel ->
   role -> role subdir

 - Source file addition to the build

 - Dependent library path resolution... this is now a private thing
   in the child CMakeLists.txt, it just passes back any adaptations
   to include_directories() and the LIB_LIST without filling the
   parent namespace with the details
2020-05-27 08:40:12 +01:00
Andy Green
cabe021955 esp32: shift to support latest esp-idf
Esp-idf has an improved but still kind of abused cmake-
based build system now.

If we see ESP_PLATFORM coming as a cmake var, we can know we
are being built from inside the esp-idf config system.

Leave the existing esp32 arrangements alone but triggered off
ESP_PLATFORM, adapt to use the cross toolchain file and
various quirks automatically.

In this way you can build lws a part of your project in a
much cleaner way.

Prepare a minimal esp32 test app for use in Sai

Adapt .sai.json to build for esp32
2020-05-27 08:40:12 +01:00
Andy Green
71f6f9a1f9 win: deal with FD_CONNECT better
POSIX connect() specifies it will signal POLLOUT available when
the connect result is available.  But windows has some non-posix
nonsense.

Improve the plat support to simulate the missing POLLOUT.
2020-05-27 08:40:12 +01:00
Andy Green
36ec353dac client: allow setting overall connect timeout from vh init
Add a member to the vh init struct allowing control of the overall
connection wait introduced in an earlier patch.  Set it to 20s
by default.


The timeout_secs member controls the individual DNS result
connect timeout and is reduced to 5s by default.
2020-05-26 17:05:39 +01:00
Andy Green
9f1d019352 CTest: migrate and deprecate existing selftest scripts
Replace the bash selftest plumbing with CTest.

To use the selftests, build with -DLWS_WITH_MINIMAL_EXAMPLES=1
and `CTEST_OUTPUT_ON_FAILURE=1 make test` or just
`make test`.

To disable tests that require internet access, also give
-DLWS_CTEST_INTERNET_AVAILABLE=0

Remove travis and appveyor scripts on master.

Remove travis and appveyor decals on README.md.
2020-05-11 15:40:13 +01:00
Andy Green
641831b3c5 context: if linux and fd_limit_per_thread set try to configure by setrlimit 2020-05-06 09:06:24 +01:00
Andy Green
3d995cf7c5 fds: add sanity checks 2020-05-05 06:34:58 +01:00
Andy Green
c95706a17f ntpclient: add plat-specific init with env var LWS_NTP_SERVER able to set it on unix and windows
Trying to use a remote pool is very variable with CI, the builder can
force a local ntpd this way cleanly.

When enabled all the test apps use ntpclient, so this lets us tell them all to
go to the local ntpd in one hit.
2020-04-25 15:11:21 +01:00
Andy Green
e72fe1bc4d unix: try to work around externally closed fds 2020-04-23 08:27:12 +01:00
huangkaicheng
974b65a2f0 iOS: detect and avoid net/route.h
LWS builds OK on iOS SDK as unix type plat, except it
doesn't have net/route.h.

Detect we're building on iOS at CMake and export a
preprocessor define we can use to snip out the missing
include.
2020-04-23 06:30:11 +01:00
Andy Green
7399f82959 spawn: CLOEXEC the wsi fds earlier 2020-04-19 06:15:26 +01:00
Andy Green
8299bd4191 windows: async dns find DNS server using modern api 2020-04-17 12:39:53 +01:00
Andy Green
a8ad5068e4 windows: fix service for udp and pending tls delays
UDP: call to recv() in there for unknown reasons was trashing udp

delays: pending tls (where data is buffered and no pending POLLIN)
was not reflected in forcing the wait to 0 properly.
2020-04-17 12:39:53 +01:00
Andy Green
d5cb0c6aa3 async-dns: cope with larger resolv.conf
Eg, systemd-resolved produces a huge comment at the start of its
default resolv.conf.  Buffer it into the pt_serv_buf to cope.
2020-04-17 12:39:53 +01:00
Andy Green
63c8a23776 lws_spawn: windows
Move the unix spawn.c from lib/misc through to lib/plat/unix, and
add an implementation for windows in lib/plat/windows
2020-04-13 19:29:09 +01:00
Andy Green
ff53a89db2 windows: async dns: fix typo 2020-04-10 17:49:19 +01:00
Andy Green
1a8833dcfd windows: ipv6 compile fix
Via turtiain

https://github.com/warmcat/libwebsockets/issues/1880
2020-04-07 10:09:00 +01:00
Andy Green
be32d0554e mbedtls: attempt to remove dependency on net_sockets.c
The mbedtls openssl wrapper wants to use exports from mbedtls' net_sockets.c,
but this is only supposed to work on *nix and windows.  Typically people
are using mbedtls on RTOS type platforms and to use it, net_sockets.c
needs some hacking.

Try to avoid that situation by porting the two exports we need into the
lws plat code and call from the wrapper.
2020-03-27 13:24:44 +00:00
Andy Green
0e94683897 freertos: forward-port lwip version adaptations 2020-03-04 12:17:49 +00:00