diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-27 19:15:22 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-27 19:15:22 +0100 |
| commit | 8fb1c09df1540aa3fca1148bed6a08ffc3090669 (patch) | |
| tree | eb03f2a9f3eb8e074abc0533aac7f5ab7cd8926c /opentracker.c | |
| parent | df5557705764d5e8f904a31d549fc037f5b1cf47 (diff) | |
All OSes now do have a cheap monotonic clock, so no caching thread is needed. Also add some relative time helpers
Diffstat (limited to 'opentracker.c')
| -rw-r--r-- | opentracker.c | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/opentracker.c b/opentracker.c index 11da486..6271b9e 100644 --- a/opentracker.c +++ b/opentracker.c | |||
| @@ -39,7 +39,6 @@ | |||
| 39 | #include "trackerlogic.h" | 39 | #include "trackerlogic.h" |
| 40 | 40 | ||
| 41 | /* Globals */ | 41 | /* Globals */ |
| 42 | time_t g_now_seconds; | ||
| 43 | uint32_t g_tracker_id; | 42 | uint32_t g_tracker_id; |
| 44 | volatile int g_opentracker_running = 1; | 43 | volatile int g_opentracker_running = 1; |
| 45 | int g_self_pipe[2]; | 44 | int g_self_pipe[2]; |
| @@ -203,7 +202,7 @@ static void handle_write(const int64_t sock) { | |||
| 203 | waiting to write and go back to waiting for the next request */ | 202 | waiting to write and go back to waiting for the next request */ |
| 204 | http_interest_drop(sock, cookie, EVENT_OUT); | 203 | http_interest_drop(sock, cookie, EVENT_OUT); |
| 205 | http_interest_add(sock, cookie, EVENT_IN); | 204 | http_interest_add(sock, cookie, EVENT_IN); |
| 206 | fdstate_set_expiry(sock, g_now_seconds + OT_CLIENT_TIMEOUT); | 205 | fdstate_set_expiry(sock, time_future_seconds(OT_CLIENT_TIMEOUT)); |
| 207 | } else | 206 | } else |
| 208 | handle_dead(sock); | 207 | handle_dead(sock); |
| 209 | } | 208 | } |
| @@ -226,7 +225,7 @@ static void handle_accept(const int64_t serversocket) { | |||
| 226 | memcpy(cookie->ip, ip, sizeof(ot_ip6)); | 225 | memcpy(cookie->ip, ip, sizeof(ot_ip6)); |
| 227 | cookie->interest = EVENT_IN; | 226 | cookie->interest = EVENT_IN; |
| 228 | 227 | ||
| 229 | if (event_add((int)sock, EVENT_IN, fdstate_open(sock, cookie, g_now_seconds + OT_CLIENT_TIMEOUT)) == -1) { | 228 | if (event_add((int)sock, EVENT_IN, fdstate_open(sock, cookie, time_future_seconds(OT_CLIENT_TIMEOUT))) == -1) { |
| 230 | fdstate_close(sock); | 229 | fdstate_close(sock); |
| 231 | free(cookie); | 230 | free(cookie); |
| 232 | close((int)sock); | 231 | close((int)sock); |
| @@ -242,7 +241,7 @@ static void handle_accept(const int64_t serversocket) { | |||
| 242 | 241 | ||
| 243 | static void *server_mainloop(void *args) { | 242 | static void *server_mainloop(void *args) { |
| 244 | struct ot_workstruct ws; | 243 | struct ot_workstruct ws; |
| 245 | time_t next_timeout_check = g_now_seconds + OT_CLIENT_TIMEOUT_CHECKINTERVAL; | 244 | time_t next_timeout_check = time_future_seconds(OT_CLIENT_TIMEOUT_CHECKINTERVAL); |
| 246 | struct iovec *iovector; | 245 | struct iovec *iovector; |
| 247 | size_t iovec_entries; | 246 | size_t iovec_entries; |
| 248 | int is_partial; | 247 | int is_partial; |
| @@ -461,17 +460,7 @@ int drop_privileges(const char *const serveruser, const char *const serverdir) { | |||
| 461 | } | 460 | } |
| 462 | 461 | ||
| 463 | /* Maintain our copy of the clock. time() on BSDs is very expensive. */ | 462 | /* Maintain our copy of the clock. time() on BSDs is very expensive. */ |
| 464 | static void *time_caching_worker(void *args) { | ||
| 465 | (void)args; | ||
| 466 | while (1) { | ||
| 467 | g_now_seconds = time(NULL); | ||
| 468 | sleep(5); | ||
| 469 | } | ||
| 470 | return NULL; | ||
| 471 | } | ||
| 472 | |||
| 473 | int main(int argc, char **argv) { | 463 | int main(int argc, char **argv) { |
| 474 | pthread_t thread_id; /* time cacher */ | ||
| 475 | 464 | ||
| 476 | random_init(); | 465 | random_init(); |
| 477 | if (fdstate_init() == -1) | 466 | if (fdstate_init() == -1) |
| @@ -492,8 +481,6 @@ int main(int argc, char **argv) { | |||
| 492 | if (drop_privileges(g_serveruser ? g_serveruser : "nobody", g_serverdir) == -1) | 481 | if (drop_privileges(g_serveruser ? g_serveruser : "nobody", g_serverdir) == -1) |
| 493 | panic("drop_privileges failed, exiting. Last error"); | 482 | panic("drop_privileges failed, exiting. Last error"); |
| 494 | 483 | ||
| 495 | g_now_seconds = time(NULL); | ||
| 496 | pthread_create(&thread_id, NULL, time_caching_worker, NULL); | ||
| 497 | 484 | ||
| 498 | /* Create our self pipe which allows us to interrupt mainloops | 485 | /* Create our self pipe which allows us to interrupt mainloops |
| 499 | wait in case some data is available to send out */ | 486 | wait in case some data is available to send out */ |
