![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Data Structures | |
| struct | N_CLOCK_SYNC |
| clock synchronization estimator More... | |
Macros | |
| #define | N_CLOCK_SYNC_INTERVAL 3.0 |
| default interval between sync requests in seconds | |
| #define | N_CLOCK_SYNC_SAMPLE_COUNT 11 |
| number of samples for the median filter | |
Functions | |
| 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_SYNC * | n_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. | |
| 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) | |
| struct N_CLOCK_SYNC |
clock synchronization estimator
Definition at line 77 of file n_clock_sync.h.
Collaboration diagram for N_CLOCK_SYNC:| #define N_CLOCK_SYNC_INTERVAL 3.0 |
default interval between sync requests in seconds
Definition at line 73 of file n_clock_sync.h.
| #define N_CLOCK_SYNC_SAMPLE_COUNT 11 |
number of samples for the median filter
Definition at line 68 of file n_clock_sync.h.
|
static |
comparison function for qsort on doubles
Definition at line 39 of file n_clock_sync.c.
Referenced by median_of().
Here is the caller graph for this function:
|
static |
compute the median of an array of doubles
Definition at line 48 of file n_clock_sync.c.
References cmp_double(), and N_CLOCK_SYNC_SAMPLE_COUNT.
Referenced by n_clock_sync_process_response().
Here is the call graph for this function:
Here is the caller graph for this function:| void n_clock_sync_delete | ( | N_CLOCK_SYNC ** | cs | ) |
free a clock sync estimator
Definition at line 78 of file n_clock_sync.c.
References __n_assert, and Free.
Referenced by run_client().
Here is the caller graph for this function:| void n_clock_sync_mark_sent | ( | N_CLOCK_SYNC * | cs, |
| double | local_now | ||
| ) |
mark that a sync request was just sent
Definition at line 125 of file n_clock_sync.c.
References __n_assert, and N_CLOCK_SYNC::last_sync_time.
Referenced by run_client().
Here is the caller graph for this function:| N_CLOCK_SYNC * n_clock_sync_new | ( | void | ) |
allocate and initialize a new clock sync estimator
Definition at line 62 of file n_clock_sync.c.
References __n_assert, N_CLOCK_SYNC::estimated_offset, N_CLOCK_SYNC::estimated_rtt, N_CLOCK_SYNC::last_sync_time, Malloc, N_CLOCK_SYNC_INTERVAL, N_CLOCK_SYNC::sample_count, and N_CLOCK_SYNC::sample_index.
Referenced by run_client().
Here is the caller graph for this function:| 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.
Updates estimated_offset and estimated_rtt. Returns TRUE on success, FALSE on error.
Definition at line 85 of file n_clock_sync.c.
References __n_assert, N_CLOCK_SYNC::estimated_offset, N_CLOCK_SYNC::estimated_rtt, LOG_DEBUG, LOG_ERR, median_of(), N_CLOCK_SYNC_SAMPLE_COUNT, n_log, N_CLOCK_SYNC::offset_samples, N_CLOCK_SYNC::rtt_samples, N_CLOCK_SYNC::sample_count, and N_CLOCK_SYNC::sample_index.
Referenced by run_client().
Here is the call graph for this function:
Here is the caller graph for this function:| double n_clock_sync_server_time | ( | const N_CLOCK_SYNC * | cs, |
| double | local_now | ||
| ) |
get estimated server time given a local time value
Definition at line 115 of file n_clock_sync.c.
References __n_assert, and N_CLOCK_SYNC::estimated_offset.
Referenced by run_client().
Here is the caller graph for this function:| 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)
Definition at line 120 of file n_clock_sync.c.
References __n_assert, N_CLOCK_SYNC::last_sync_time, and N_CLOCK_SYNC_INTERVAL.
Referenced by run_client().
Here is the caller graph for this function: