static char *timeserver = NULL;
static gint poll_id = 0;
+static gint timeout_id = 0;
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)
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.
*/
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;
}
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;
DBG("status %d", status);
+ __sync_fetch_and_add(&count, 1);
+
if (status == G_RESOLV_RESULT_STATUS_SUCCESS) {
if (results != NULL) {
for (i = 0; results[i]; i++)
return;
}
}
- __sync_fetch_and_add(&count, 1);
+
__connman_timeserver_sync_next();
}