#define ARES_DEFAULT_TRIAL_TIMEOUT_MS 500
#define ARES_DEFAULT_TIMEOUT_MS 5000
#define ARES_DEFAULT_TRY 10
+#define ARES_PROCESS_INTERVAL_USEC 100000
#define DEFAULT_TEST_URL "www.tizen.org"
#define DNS_INTERVAL_MIN 1000
static gboolean __sock_channel_io_cb(GIOChannel *source,
GIOCondition condition, gpointer data)
{
- INM_LOGI("");
inm_gio_channel_s *gio_channel;
ares_socket_t read_fd = ARES_SOCKET_BAD;
ares_socket_t write_fd = ARES_SOCKET_BAD;
if (g_default_dns_lookup_data->is_lookup_finished)
__destroy_default_dns_lookup_data();
- INM_LOGI("");
+
+ g_usleep(ARES_PROCESS_INTERVAL_USEC);
+
return TRUE;
}
return;
}
-static int __ares_set_opt(inm_dns_lookup_s *lookup_data)
+static int __ares_set_opt(inm_dns_lookup_s *lookup_data, int monitor_interval)
{
struct ares_options *p_opts = NULL;
p_opts = g_try_malloc0(sizeof(struct ares_options));
if (!p_opts) {
- INM_LOGI("");
+ INM_LOGI("Out of memory");
return -1;
}
- p_opts->sock_state_cb = __sock_state_cb;
- p_opts->sock_state_cb_data = (void *)lookup_data;
- p_opts->timeout = ARES_DEFAULT_TRIAL_TIMEOUT_MS;
- p_opts->tries = ARES_DEFAULT_TRY;
+ if (monitor_interval) {
+ int monitor_timeout = ARES_DEFAULT_TIMEOUT_MS;
+
+ if (ARES_DEFAULT_TIMEOUT_MS >= monitor_interval)
+ monitor_timeout = (int)(monitor_interval * 0.8);
+
+ p_opts->timeout = monitor_timeout;
+ p_opts->sock_state_cb = __sock_state_cb;
+ p_opts->sock_state_cb_data = (void *)lookup_data;
+ } else {
+ p_opts->sock_state_cb = __sock_state_cb;
+ p_opts->sock_state_cb_data = (void *)lookup_data;
+ p_opts->timeout = ARES_DEFAULT_TRIAL_TIMEOUT_MS;
+ p_opts->tries = ARES_DEFAULT_TRY;
+ }
lookup_data->ch_options = p_opts;
return 0;
}
-static inline int __init_ares_channel(inm_dns_lookup_s *dns_lookup_data)
+static inline int __init_ares_channel(inm_dns_lookup_s *dns_lookup_data, int monitor_interval)
{
ares_channel ch;
int opt_mask = 0;
int ret;
- opt_mask = ARES_OPT_TIMEOUTMS | ARES_OPT_TRIES | ARES_OPT_SOCK_STATE_CB;
+ if (monitor_interval)
+ opt_mask = ARES_OPT_TIMEOUTMS | ARES_OPT_SOCK_STATE_CB;
+ else
+ opt_mask = ARES_OPT_TIMEOUTMS | ARES_OPT_TRIES | ARES_OPT_SOCK_STATE_CB;
+
ret = ares_init_options(&ch, dns_lookup_data->ch_options, opt_mask);
if (ret != ARES_SUCCESS) {
PRINT_LOG("ares_init_options: %s\n", ares_strerror(ret));
return 0;
}
-static inline int __create_default_dns_lookup_data()
+static inline int __create_default_dns_lookup_data(int monitor_interval)
{
inm_dns_lookup_s *dns_lookup_data = NULL;
int ret;
dns_lookup_data = g_try_malloc0(sizeof(inm_dns_lookup_s));
if (!dns_lookup_data) {
- INM_LOGI("");
+ INM_LOGI("Out of memory");
return -1;
}
- ret = __ares_set_opt(dns_lookup_data);
+ ret = __ares_set_opt(dns_lookup_data, monitor_interval);
if (ret != 0) {
- INM_LOGI("");
+ INM_LOGI("__ares_set_opt() is failed");
g_free(dns_lookup_data);
return -1;
}
- ret = __init_ares_channel(dns_lookup_data);
+ ret = __init_ares_channel(dns_lookup_data, monitor_interval);
if (ret != 0) {
- INM_LOGI("");
+ INM_LOGI("__init_ares_channel() is failed");
g_free(dns_lookup_data->ch_options);
g_free(dns_lookup_data);
return -1;
__destroy_default_dns_lookup_data();
}
- ret = __create_default_dns_lookup_data();
+ interval = __get_dns_check_interval_value();
+
+ ret = __create_default_dns_lookup_data(interval);
if (ret != 0) {
INM_LOGI("Operation Failed");
return INM_DNS_LOOKUP_ERROR_OPERATION_FAILED;
}
- interval = __get_dns_check_interval_value();
-
__dns_state_monitor(NULL);
g_default_dns_lookup_data->ares_timer_source_id =
return INM_DNS_LOOKUP_ERROR_IN_PROGRESS;
}
- ret = __create_default_dns_lookup_data();
+ ret = __create_default_dns_lookup_data(0);
if (ret != 0) {
INM_LOGI("");
return INM_DNS_LOOKUP_ERROR_OPERATION_FAILED;