summaryrefslogtreecommitdiff
path: root/src/ntp.c
diff options
context:
space:
mode:
authorAlok Barsode <alok.barsode@linux.intel.com>2012-02-03 20:26:01 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2012-02-04 01:15:36 +0100
commitf97c14e2606c64df0ae23c81a8a4066d27367091 (patch)
tree733f1bc5f24d4a051193c947f670c8910a9eb72c /src/ntp.c
parent8f3c51386929c432af4d78c1e8ab1d82a1f6ac8b (diff)
downloadconnman-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.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/ntp.c b/src/ntp.c
index 4d3cd888..cbe5a3be 100644
--- a/src/ntp.c
+++ b/src/ntp.c
@@ -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;