smartdns: enhance reliability during initialization.

This commit is contained in:
Nick Peng
2023-11-14 22:18:06 +08:00
parent 79a49c6bd6
commit 568f95dbdf
9 changed files with 85 additions and 12 deletions

View File

@@ -267,7 +267,7 @@ struct dns_query_struct {
/* replied hash table */
DECLARE_HASHTABLE(replied_map, 4);
};
static int is_client_init;
static struct dns_client client;
static LIST_HEAD(pending_servers);
static pthread_mutex_t pending_server_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -4362,6 +4362,10 @@ int dns_client_init(void)
int fd_wakeup = -1;
int ret = 0;
if (is_client_init == 1) {
return -1;
}
if (client.epoll_fd > 0) {
return -1;
}
@@ -4411,6 +4415,7 @@ int dns_client_init(void)
}
client.fd_wakeup = fd_wakeup;
is_client_init = 1;
return 0;
errout:
@@ -4437,6 +4442,10 @@ errout:
void dns_client_exit(void)
{
if (is_client_init == 0) {
return;
}
if (client.tid) {
void *ret = NULL;
atomic_set(&client.run, 0);
@@ -4458,4 +4467,6 @@ void dns_client_exit(void)
SSL_CTX_free(client.ssl_ctx);
client.ssl_ctx = NULL;
}
is_client_init = 0;
}