diff options
author | Alok Barsode <alok.barsode@linux.intel.com> | 2012-02-03 20:26:01 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-02-04 01:15:36 +0100 |
commit | f97c14e2606c64df0ae23c81a8a4066d27367091 (patch) | |
tree | 733f1bc5f24d4a051193c947f670c8910a9eb72c /src/ntp.c | |
parent | 8f3c51386929c432af4d78c1e8ab1d82a1f6ac8b (diff) | |
download | connman-f97c14e2606c64df0ae23c81a8a4066d27367091.tar.gz connman-f97c14e2606c64df0ae23c81a8a4066d27367091.tar.bz2 connman-f97c14e2606c64df0ae23c81a8a4066d27367091.zip |
ntp: Add timeserver switch logic
Add a timeout mechanism to switch to next system timeserver
if the current one does not respond or is a bogus one.
Diffstat (limited to 'src/ntp.c')
-rw-r--r-- | src/ntp.c | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -75,6 +75,7 @@ static int transmit_fd = 0; static char *timeserver = NULL; static gint poll_id = 0; +static gint timeout_id = 0; static void send_packet(int fd, const char *server) { @@ -109,6 +110,18 @@ static void send_packet(int fd, const char *server) } } +static gboolean next_server(gpointer user_data) +{ + if (timeserver != NULL) { + g_free(timeserver); + timeserver = NULL; + } + + __connman_timeserver_sync_next(); + + return FALSE; +} + static gboolean next_poll(gpointer user_data) { if (timeserver == NULL || transmit_fd == 0) @@ -168,7 +181,11 @@ static void decode_msg(void *base, size_t len, struct timeval *tv) DBG("offset=%f delay=%f", offset, delay); - /* Timeserver has responded. + /* Remove the timeout, as timeserver has responded */ + if (timeout_id > 0) + g_source_remove(timeout_id); + + /* * Now poll the server every transmit_delay seconds * for time correction. */ @@ -341,6 +358,13 @@ int __connman_ntp_start(char *server) start_ntp(timeserver); + /* + * Add a fallback timeout , preferably longer, 16 sec here, + * to fallback on the next server. + */ + + timeout_id = g_timeout_add_seconds(16, next_server, NULL); + return 0; } @@ -351,6 +375,9 @@ void __connman_ntp_stop() if (poll_id > 0) g_source_remove(poll_id); + if (timeout_id > 0) + g_source_remove(timeout_id); + if (channel_watch > 0) { g_source_remove(channel_watch); channel_watch = 0; |