kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 6072828d8f78310b331c4fdcf50e5257b85ff801
parent d86a10afa10b7dc15f736f9780ec177269ff02b1
Author: Joris Vink <joris@coders.se>
Date:   Fri, 24 Jan 2020 19:36:32 +0100

Improve BSD platform event code.

Instead of adding all listening sockets into the kqueue at platform init,
do it in the first call to kore_platform_enable_accept().

This way a worker process can still call kore_server_create() in its
kore_worker_configure() hook.

Diffstat:
src/bsd.c | 26++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/bsd.c b/src/bsd.c @@ -38,6 +38,7 @@ #endif static int kfd = -1; +static int scheduled = 0; static struct kevent *events = NULL; static u_int32_t event_count = 0; @@ -78,9 +79,6 @@ kore_platform_worker_setcpu(struct kore_worker *kw) void kore_platform_event_init(void) { - struct listener *l; - struct kore_server *srv; - if (kfd != -1) close(kfd); if (events != NULL) @@ -91,18 +89,6 @@ kore_platform_event_init(void) event_count = (worker_max_connections * 2) + nlisteners; events = kore_calloc(event_count, sizeof(struct kevent)); - - /* Hack to check if we're running under the parent or not. */ - if (worker != NULL) { - LIST_FOREACH(srv, &kore_servers, list) { - LIST_FOREACH(l, &srv->listeners, list) { - if (l->fd == -1) - continue; - kore_platform_event_schedule(l->fd, - EVFILT_READ, EV_ADD | EV_DISABLE, l); - } - } - } } void @@ -188,11 +174,19 @@ kore_platform_enable_accept(void) { struct listener *l; struct kore_server *srv; + int flags; + + if (scheduled == 0) { + scheduled = 1; + flags = EV_ADD | EV_ENABLE; + } else { + flags = EV_ENABLE; + } LIST_FOREACH(srv, &kore_servers, list) { LIST_FOREACH(l, &srv->listeners, list) { kore_platform_event_schedule(l->fd, - EVFILT_READ, EV_ENABLE, l); + EVFILT_READ, flags, l); } } }