mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00

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
76 lines
1.5 KiB
C
76 lines
1.5 KiB
C
/*
|
|
* lws-minimal-http-server-eventlib-foreign
|
|
*
|
|
* Written in 2010-2020 by Andy Green <andy@warmcat.com>
|
|
*
|
|
* This file is made available under the Creative Commons CC0 1.0
|
|
* Universal Public Domain Dedication.
|
|
*
|
|
* The libev specific code
|
|
*/
|
|
|
|
#include <libwebsockets.h>
|
|
|
|
#include <ev.h>
|
|
|
|
#include <string.h>
|
|
#include <signal.h>
|
|
|
|
#include "private.h"
|
|
|
|
static struct ev_loop *loop_ev;
|
|
static struct ev_timer timer_outer_ev;
|
|
static struct ev_signal sighandler_ev;
|
|
|
|
static void
|
|
timer_cb_ev(struct ev_loop *loop, struct ev_timer *watcher, int revents)
|
|
{
|
|
foreign_timer_service(loop_ev);
|
|
}
|
|
|
|
static void
|
|
signal_cb_ev(struct ev_loop *loop, struct ev_signal *watcher, int revents)
|
|
{
|
|
signal_cb(watcher->signum);
|
|
}
|
|
|
|
static void
|
|
foreign_event_loop_init_and_run_libev(void)
|
|
{
|
|
/* we create and start our "foreign loop" */
|
|
|
|
loop_ev = ev_loop_new(0);
|
|
|
|
ev_signal_init(&sighandler_ev, signal_cb_ev, SIGINT);
|
|
ev_signal_start(loop_ev, &sighandler_ev);
|
|
|
|
ev_timer_init(&timer_outer_ev, timer_cb_ev, 0, 1);
|
|
ev_timer_start(loop_ev, &timer_outer_ev);
|
|
|
|
ev_run(loop_ev, 0);
|
|
}
|
|
|
|
static void
|
|
foreign_event_loop_stop_libev(void)
|
|
{
|
|
ev_break(loop_ev, EVBREAK_ALL);
|
|
}
|
|
|
|
static void
|
|
foreign_event_loop_cleanup_libev(void)
|
|
{
|
|
/* cleanup the foreign loop assets */
|
|
|
|
ev_timer_stop(loop_ev, &timer_outer_ev);
|
|
ev_signal_stop(loop_ev, &sighandler_ev);
|
|
|
|
ev_run(loop_ev, 0);
|
|
ev_loop_destroy(loop_ev);
|
|
}
|
|
|
|
const struct ops ops_libev = {
|
|
foreign_event_loop_init_and_run_libev,
|
|
foreign_event_loop_stop_libev,
|
|
foreign_event_loop_cleanup_libev
|
|
};
|
|
|