X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fntp.c;h=91a8832dc05fc9c6d5ce9f5aa436cd73ee9ba816;hb=57156cc5738cfbf60e1b0ddf444ad6eec5964a0d;hp=4d3cd888e79ec9d32aef19794a92e9af012dcb99;hpb=8f3c51386929c432af4d78c1e8ab1d82a1f6ac8b;p=framework%2Fconnectivity%2Fconnman.git diff --git a/src/ntp.c b/src/ntp.c index 4d3cd88..91a8832 100644 --- a/src/ntp.c +++ b/src/ntp.c @@ -2,7 +2,7 @@ * * Connection Manager * - * Copyright (C) 2007-2010 Intel Corporation. All rights reserved. + * Copyright (C) 2007-2012 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -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. */ @@ -179,6 +196,8 @@ static void decode_msg(void *base, size_t len, struct timeval *tv) poll_id = g_timeout_add_seconds(transmit_delay, next_poll, NULL); + connman_info("ntp: time slew %+.6f s", offset); + if (offset < STEPTIME_MIN_OFFSET && offset > -STEPTIME_MIN_OFFSET) { struct timeval adj; @@ -341,6 +360,13 @@ int __connman_ntp_start(char *server) start_ntp(timeserver); + /* + * Add a fallback timeout , preferably short, 5 sec here, + * to fallback on the next server. + */ + + timeout_id = g_timeout_add_seconds(5, next_server, NULL); + return 0; } @@ -351,6 +377,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;