diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-25 18:51:51 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-25 18:51:51 +0100 |
| commit | 2c7659ec930277981b6333b5b3aff7840d11933c (patch) | |
| tree | 1c363ce905ef1a62395f398335a94a47916af278 /ot_udp.c | |
| parent | 632960a33eb8d23925b2bbef24d5065de7280aef (diff) | |
Decouple config parsing from binding and worker spawning
* Options are parsed now into a listener description list before
binding them at once and starting the workers later
* UDP workers can now be configured per connection
* socket reuse is now done more sensibly, mcast sockets always
reused
* Hold-off logic after spawning udp workers removed
Diffstat (limited to 'ot_udp.c')
| -rw-r--r-- | ot_udp.c | 24 |
1 files changed, 7 insertions, 17 deletions
| @@ -26,9 +26,6 @@ static uint32_t g_rijndael_round_key[44] = {0}; | |||
| 26 | static volatile uint32_t g_key_of_the_hour[2] = {0}; | 26 | static volatile uint32_t g_key_of_the_hour[2] = {0}; |
| 27 | static volatile ot_time g_hour_of_the_key; | 27 | static volatile ot_time g_hour_of_the_key; |
| 28 | 28 | ||
| 29 | static pthread_mutex_t udp_start_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
| 30 | static pthread_cond_t udp_start_cond = PTHREAD_COND_INITIALIZER; | ||
| 31 | static int g_opentracker_started = 0; | ||
| 32 | 29 | ||
| 33 | static void udp_generate_rijndael_round_key(void) { | 30 | static void udp_generate_rijndael_round_key(void) { |
| 34 | uint32_t key[16]; | 31 | uint32_t key[16]; |
| @@ -211,11 +208,6 @@ static void *udp_worker(void *args) { | |||
| 211 | ws.debugbuf = malloc(G_DEBUGBUF_SIZE); | 208 | ws.debugbuf = malloc(G_DEBUGBUF_SIZE); |
| 212 | #endif | 209 | #endif |
| 213 | 210 | ||
| 214 | pthread_mutex_lock(&udp_start_mutex); | ||
| 215 | while(g_opentracker_running && !g_opentracker_started) | ||
| 216 | pthread_cond_wait(&udp_start_cond, &udp_start_mutex); | ||
| 217 | pthread_mutex_unlock(&udp_start_mutex); | ||
| 218 | |||
| 219 | while (g_opentracker_running) | 211 | while (g_opentracker_running) |
| 220 | handle_udp6(sock, &ws); | 212 | handle_udp6(sock, &ws); |
| 221 | 213 | ||
| @@ -227,20 +219,18 @@ static void *udp_worker(void *args) { | |||
| 227 | return NULL; | 219 | return NULL; |
| 228 | } | 220 | } |
| 229 | 221 | ||
| 230 | void udp_init(int64_t sock, unsigned int worker_count) { | 222 | void udp_init(void) { |
| 231 | pthread_t thread_id; | ||
| 232 | if (!g_rijndael_round_key[0]) | 223 | if (!g_rijndael_round_key[0]) |
| 233 | udp_generate_rijndael_round_key(); | 224 | udp_generate_rijndael_round_key(); |
| 225 | } | ||
| 226 | |||
| 227 | void udp_workers_install(int64_t sock, unsigned int worker_count) { | ||
| 228 | pthread_t thread_id; | ||
| 229 | |||
| 234 | #ifdef _DEBUG | 230 | #ifdef _DEBUG |
| 235 | fprintf(stderr, " installing %d workers on udp socket %ld\n", worker_count, (unsigned long)sock); | 231 | fprintf(stderr, "Installing %d workers on udp socket %ld\n", worker_count, (unsigned long)sock); |
| 236 | #endif | 232 | #endif |
| 237 | while (worker_count--) | 233 | while (worker_count--) |
| 238 | pthread_create(&thread_id, NULL, udp_worker, (void *)sock); | 234 | pthread_create(&thread_id, NULL, udp_worker, (void *)sock); |
| 239 | } | 235 | } |
| 240 | 236 | ||
| 241 | void udp_kickoff(void) { | ||
| 242 | pthread_mutex_lock(&udp_start_mutex); | ||
| 243 | g_opentracker_started = 1; | ||
| 244 | pthread_cond_broadcast(&udp_start_cond); | ||
| 245 | pthread_mutex_unlock(&udp_start_mutex); | ||
| 246 | } | ||
