Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9239f11

Browse files
committedDec 14, 2020
add support for systemd event loop
1 parent 736f073 commit 9239f11

9 files changed

+464
-1
lines changed
 

‎CMakeLists-implied-options.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ if(LWS_WITH_DISTRO_RECOMMENDED)
8787
set(LWS_WITH_LIBUV 1) # libuv
8888
set(LWS_WITH_LIBEV 1) # libev
8989
set(LWS_WITH_LIBEVENT 1) # libevent
90+
set(LWS_WITH_SDEVENT 0) # sd-event
9091
set(LWS_WITH_EVLIB_PLUGINS 1) # event libraries created as plugins / individual packages
9192
set(LWS_WITHOUT_EXTENSIONS 0) # libz
9293
set(LWS_ROLE_DBUS 1) # dbus-related libs
@@ -117,7 +118,8 @@ endif()
117118
if (LWS_WITH_LIBEV OR
118119
LWS_WITH_LIBUV OR
119120
LWS_WITH_LIBEVENT OR
120-
LWS_WITH_GLIB)
121+
LWS_WITH_GLIB OR
122+
LWS_WITH_SDEVENT)
121123
set(LWS_WITH_EVENT_LIBS 1)
122124
else()
123125
unset(LWS_WITH_EVENT_LIBS)

‎CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ option(LWS_WITH_LIBEV "Compile with support for libev" OFF)
152152
option(LWS_WITH_LIBUV "Compile with support for libuv" OFF)
153153
option(LWS_WITH_LIBEVENT "Compile with support for libevent" OFF)
154154
option(LWS_WITH_GLIB "Compile with support for glib event loop" OFF)
155+
option(LWS_WITH_SDEVENT "Compile with support for sd-event loop" OFF)
155156

156157
if (UNIX)
157158
# since v4.1, on unix platforms default is build any event libs as runtime plugins

‎cmake/lws_config.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
#cmakedefine LWS_WITH_LIBEV
151151
#cmakedefine LWS_WITH_LIBEVENT
152152
#cmakedefine LWS_WITH_LIBUV
153+
#cmakedefine LWS_WITH_SDEVENT
153154
#cmakedefine LWS_WITH_LWSAC
154155
#cmakedefine LWS_LOGS_TIMESTAMP
155156
#cmakedefine LWS_WITH_MBEDTLS

‎include/libwebsockets/lws-context-vhost.h

+3
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@
230230
/**< (CTX) Disable lws_system state, eg, because we are a secure streams
231231
* proxy client that is not trying to track system state by itself. */
232232

233+
#define LWS_SERVER_OPTION_SDEVENT (1ll << 36)
234+
/**< (CTX) Use sd-event loop */
235+
233236
/****** add new things just above ---^ ******/
234237

235238

‎lib/core/context.c

+8
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ static const struct lws_evlib_map {
340340
{ LWS_SERVER_OPTION_LIBEVENT, "evlib_event" },
341341
{ LWS_SERVER_OPTION_GLIB, "evlib_glib" },
342342
{ LWS_SERVER_OPTION_LIBEV, "evlib_ev" },
343+
{ LWS_SERVER_OPTION_SDEVENT, "evlib_sd" },
343344
};
344345
static const char * const dlist[] = {
345346
LWS_INSTALL_LIBDIR,
@@ -520,6 +521,13 @@ lws_create_context(const struct lws_context_creation_info *info)
520521
}
521522
#endif
522523

524+
#if defined(LWS_WITH_SDEVENT)
525+
if (lws_check_opt(info->options, LWS_SERVER_OPTION_SDEVENT)) {
526+
extern const lws_plugin_evlib_t evlib_sd;
527+
plev = &evlib_sd;
528+
}
529+
#endif
530+
523531
#endif /* with event libs */
524532

525533
#endif /* not with ev plugins */

‎lib/event-libs/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ if (LWS_WITH_LIBEV)
9191
set(LWS_HAVE_EVBACKEND_IOURING ${LWS_HAVE_EVBACKEND_IOURING} PARENT_SCOPE)
9292
endif()
9393

94+
if (LWS_WITH_SDEVENT)
95+
add_subdir_include_directories(sdevent)
96+
endif()
97+
9498

9599

96100
#

‎lib/event-libs/sdevent/CMakeLists.txt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# The strategy is to only export to PARENT_SCOPE
2+
#
3+
# - changes to LIB_LIST
4+
# - includes via include_directories
5+
#
6+
# and keep everything else private
7+
8+
include_directories(.)
9+
10+
# configure or find systemd library
11+
set(LIB_SYSTEMD_LIBRARIES CACHE PATH "Path to the libsystemd library")
12+
if ("${LWS_SYSTEMD_LIBRARIES}" STREQUAL "")
13+
if (NOT LIB_SYSTEMD_FOUND)
14+
find_library(LIBSYSTEMD_LIBRARIES NAMES systemd)
15+
endif()
16+
else()
17+
set(LIBSYSTEMD_LIBRARIES ${LWS_SYSTEMD_LIBRARIES})
18+
endif()
19+
message("libsystemd libraries: ${LIBSYSTEMD_LIBRARIES}")
20+
21+
if (LWS_WITH_EVLIB_PLUGINS)
22+
23+
create_evlib_plugin(
24+
evlib_sd
25+
sdevent.c
26+
private-lib-event-libs-sdevent.h
27+
${LIBSYSTEMD_LIBRARIES}
28+
)
29+
30+
else()
31+
32+
list(APPEND LIB_LIST ${LIBSYSTEMD_LIBRARIES})
33+
list(APPEND SOURCES event-libs/sdevent/sdevent.c)
34+
35+
endif()
36+
37+
#
38+
# Keep explicit parent scope exports at end
39+
#
40+
41+
exports_to_parent_scope()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <private-lib-core.h>
2+
3+
extern const struct lws_event_loop_ops event_loop_ops_sdevent;

‎lib/event-libs/sdevent/sdevent.c

+400
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.