mirror of https://git.kore.io/kore.git
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.
This commit is contained in:
parent
d86a10afa1
commit
6072828d8f
26
src/bsd.c
26
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue