-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for sd-event as event loop #1
base: v4.1-stable
Are you sure you want to change the base?
Conversation
Chrome has started being able to issue frame type 0x42, we drop the connection before we realize we wanted to ignore it. This explicitly ignores it a bit earlier.
Change-Id: I81b67cbb28591a20842fc7d6e09b78375845aae4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I miss one block of: https://github.com/defaultbranch/libwebsockets/blob/main/lib/event-libs/README.md
Enabling event lib adoption
You need to add a LWS_SERVER_OPTION... flag as necessary in ./lib/libwebsockets.h enum lws_context_options, and follow the existing code in lws_create_context() to convert the flag into binding your ops struct to the context.
CMakeLists.txt
Outdated
@@ -152,6 +152,7 @@ option(LWS_WITH_LIBEV "Compile with support for libev" OFF) | |||
option(LWS_WITH_LIBUV "Compile with support for libuv" OFF) | |||
option(LWS_WITH_LIBEVENT "Compile with support for libevent" OFF) | |||
option(LWS_WITH_GLIB "Compile with support for glib event loop" OFF) | |||
option(LWS_WITH_SDEVENT "Compile with support for systemd event loop" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
option(LWS_WITH_SDEVENT "Compile with support for systemd event loop" OFF) | |
option(LWS_WITH_SDEVENT "Compile with support for systemd event loop: sd-event" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, I wanted to keep the wording aligned with libuv/libevent/glib above.
Is "systemd event loop" ambiguous? I thought sd-event is the only systemd event loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is the only one. I only think that we could easily miss the d
in systemd and then think about raw Linux event loop or something like that. sd-event
ist much more specific. Maybe we should use only Compile with support for sd-event
instead of systemd event loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed text to "Compile with support for sd-event"
@@ -230,6 +230,9 @@ | |||
/**< (CTX) Disable lws_system state, eg, because we are a secure streams | |||
* proxy client that is not trying to track system state by itself. */ | |||
|
|||
#define LWS_SERVER_OPTION_SDEVENT (1ll << 36) | |||
/**< (CTX) Use systemd event loop */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/**< (CTX) Use systemd event loop */ | |
/**< (CTX) Use systemd event loop: sd-event */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(similar to the previous comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to "Use sd-event loop"
#endif | ||
const lws_plugin_evlib_t evlib_sd = { | ||
.hdr = { | ||
"systemd event loop", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"systemd event loop", | |
"systemd event loop: sd-event", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(similar to the previous comment)
CMakeLists-implied-options.txt
Outdated
if (LWS_WITH_SDEVENT) | ||
set(LWS_WITH_SDEVENT 1) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional and the set variable are both the exact same. What is this check intended for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this, not sure whether its a bug (could be), or it is there to ensure that anything "defined" is an integer 1 while anything undefined remains undefined (similar to what https://stackoverflow.com/questions/14751973/what-is-in-c does)
Need to check...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forwarded the question to warmcat#2130, waiting for an answer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. (The maintainers found this pointless as well.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks not too bad. But I did not completely understand everything. Maybe I will with the next review after you added more tests. So that the code can mature. Most things I noticed is the missing error handling at many points.
set(LIB_SYSTEMD_LIBRARIES CACHE PATH "Path to the libsystemd library") | ||
if ("${LWS_SYSTEMD_LIBRARIES}" STREQUAL "") | ||
if (NOT LIB_SYSTEMD_FOUND) | ||
message("searching for systemd") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this line because the find_library
command will already print something similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
|
||
if (LWS_WITH_EVLIB_PLUGINS) | ||
|
||
create_evlib_plugin(evlib_sd sdevent.c ${LIBSYSTEMD_LIBRARIES}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other implementations do also mention their private header here.
create_evlib_plugin(evlib_sd sdevent.c ${LIBSYSTEMD_LIBRARIES}) | |
create_evlib_plugin(evlib_sd sdevent.c private-lib-event-libs-sdevent.h ${LIBSYSTEMD_LIBRARIES}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
struct lws_context_eventlibs_sdevent { | ||
}; | ||
|
||
struct lws_pt_eventlibs_sdevent { | ||
struct lws_context_per_thread *pt; | ||
struct sd_event *io_loop; | ||
struct sd_event_source *sultimer; | ||
struct sd_event_source *idletimer; | ||
}; | ||
|
||
struct lws_vh_eventlibs_sdevent { | ||
}; | ||
|
||
struct lws_wsi_watcher_sdevent { | ||
struct sd_event_source *source; | ||
uint32_t events; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those should go into private-lib-event-libs-sdevent.h
@@ -0,0 +1,3 @@ | |||
#include <private-lib-core.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add the licence/copyright header in each of these source files?
sd_event_source_unref(ptpriv->sultimer); | ||
ptpriv->sultimer = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sd_event_source_unref(ptpriv->sultimer); | |
ptpriv->sultimer = NULL; | |
ptpriv->sultimer = sd_event_source_unref(ptpriv->sultimer); |
if (!(wsi_to_priv_sd(wsi)->events & (EPOLLIN | EPOLLOUT))) | ||
sd_event_source_set_enabled(wsi_to_priv_sd(wsi)->source, SD_EVENT_ONESHOT); | ||
else | ||
sd_event_source_set_enabled(wsi_to_priv_sd(wsi)->source, SD_EVENT_OFF); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All sd_event_
functions are missing error handling in this function.
|
||
sd_event_source_set_io_events(wsi_to_priv_sd(wsi)->source, wsi_to_priv_sd(wsi)->events); | ||
|
||
if (!(wsi_to_priv_sd(wsi)->events & (EPOLLIN | EPOLLOUT))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch if/else clause to make this more understandable ( no !
needed). Besides, is this even correct? If I understand correctly we do disable the event if at least one of the two event flags are set?
lib/event-libs/sdevent/sdevent.c
Outdated
eventfd.events = 0; | ||
eventfd.revents = 0; | ||
|
||
// TODO handle revents error bits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO
} | ||
|
||
lws_pt_unlock(pt); | ||
lws_context_unlock(pt->context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct to release the locks here? Because you still use pt
later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from libuv/libev.
But I will check this again...
lws_context_unlock(pt->context); | ||
|
||
return -1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All sd_event_ functions are missing error handling in this function.
When using a foreign libuv loop, context creation may fail after adding handles to the foreign loop... if so, it can no longer deal with the fatal error by unpicking the created context and returning NULL... it has to brazen it out with a half-baked context that has already started the destroy flow and allow the foreign loop to close out the handles the usual way for libuv. warmcat#2129
@langchr86 wrote:
This README is probably a bit out of date regarding the include file location. Today the enum and the new flag LWS_SERVER_OPTION_SDEVENT reside in include/libwebsockets/lws-context-vhost.h instead. |
bb1d011
to
9239f11
Compare
Generate the config file for the installation tree fix wrong LWS__INCLUDE_DIRS definition
e6fc0d8
to
8bc15ae
Compare
8bc15ae
to
8667c29
Compare
Der grösste teil vom Code steckt in
sdevent.c
.Als Vorlage habe ich libuv.c und libev.c verwendet.
Es gibt noch ein README.md zum Einbinden von Event-Loop-Bibliotheken.