Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_clock_sync.c File Reference

Clock synchronization estimator implementation. More...

#include "nilorea/n_clock_sync.h"
#include "nilorea/n_log.h"
#include "nilorea/n_common.h"
#include <string.h>
#include <stdlib.h>
+ Include dependency graph for n_clock_sync.c:

Go to the source code of this file.

Functions

static double clock_sync_effective_offset (const N_CLOCK_SYNC *cs, double local_now)
 effective (slewed) offset at local_now — pure function of the stored state so the const getter needs no mutation.
 
static void clock_sync_store_sample (N_CLOCK_SYNC *cs, double offset, double rtt, double local_now)
 store one (offset, rtt) sample and recompute the estimates.
 
static int cmp_double (const void *a, const void *b)
 comparison function for qsort on doubles
 
static double median_of (const double *samples, int count)
 compute the median of an array of doubles
 
void n_clock_sync_delete (N_CLOCK_SYNC **cs)
 free a clock sync estimator
 
void n_clock_sync_mark_sent (N_CLOCK_SYNC *cs, double local_now)
 mark that a sync request was just sent
 
N_CLOCK_SYNCn_clock_sync_new (void)
 allocate and initialize a new clock sync estimator
 
int n_clock_sync_process_response (N_CLOCK_SYNC *cs, double client_send_time, double server_time, double local_now)
 record a sync response: client_send_time is the local time the request was sent, server_time is the server's timestamp from the response, local_now is the current local time when the response was received.
 
void n_clock_sync_seed (N_CLOCK_SYNC *cs, double offset, double rtt)
 Inject a synthetic (offset, rtt) sample, e.g.
 
double n_clock_sync_server_time (const N_CLOCK_SYNC *cs, double local_now)
 get estimated server time given a local time value.
 
int n_clock_sync_should_send (const N_CLOCK_SYNC *cs, double local_now)
 check if it's time to send a new sync request (returns TRUE/FALSE).
 

Detailed Description

Clock synchronization estimator implementation.

Author
Castagnier Mickael
Version
1.1
Date
19/07/2026

Definition in file n_clock_sync.c.