commit fb8035297d6287806b47dad76278d286d6227322
parent 3b5d4a2b03c1d8c15d2f47f16bfbd743ddacb082
Author: Joris Vink <joris@coders.se>
Date: Mon, 13 Mar 2017 15:32:04 +0100
Allow workers to listen on different ports.
This commit allows worker processes to have individual listeners
not configured by the kore configuration.
If you do the following:
- do not configure listeners in your .conf file
- call kore_server_bind() in kore_worker_configure()
the workers will no longer fight over accept locks as the configured
ports no longer conflict with each other.
This allows me to create X amount of instances of a worker process that
are each individually accessible via unique ports.
Diffstat:
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/worker.c b/src/worker.c
@@ -80,6 +80,7 @@ static void worker_entropy_recv(struct kore_msg *, const void *);
#endif
static struct kore_worker *kore_workers;
+static int worker_no_lock;
static int shm_accept_key;
static struct wlock *accept_lock;
@@ -97,6 +98,8 @@ kore_worker_init(void)
size_t len;
u_int16_t i, cpu;
+ worker_no_lock = 0;
+
if (worker_count == 0)
worker_count = 1;
@@ -347,6 +350,9 @@ kore_worker_entry(struct kore_worker *kw)
kore_msg_register(KORE_MSG_ENTROPY_RESP, worker_entropy_recv);
#endif
+ if (nlisteners == 0)
+ worker_no_lock = 1;
+
kore_log(LOG_NOTICE, "worker %d started (cpu#%d)", kw->id, kw->cpu);
rcall = kore_runtime_getcall("kore_worker_configure");
@@ -498,7 +504,8 @@ kore_worker_wait(int final)
}
#endif
- if (kw->pid == accept_lock->current)
+ if (kw->pid == accept_lock->current &&
+ worker_no_lock == 0)
worker_unlock();
if (kw->active_hdlr != NULL) {
@@ -526,7 +533,7 @@ kore_worker_wait(int final)
static inline void
kore_worker_acceptlock_release(void)
{
- if (worker_count == 1)
+ if (worker_count == 1 || worker_no_lock == 1)
return;
if (worker->has_lock != 1)
@@ -544,7 +551,7 @@ kore_worker_acceptlock_obtain(void)
if (worker->has_lock == 1)
return (1);
- if (worker_count == 1) {
+ if (worker_count == 1 || worker_no_lock == 1) {
worker->has_lock = 1;
return (1);
}