aboutsummaryrefslogtreecommitdiff
path: root/client/libacron/apps/acronc/async_dns.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/libacron/apps/acronc/async_dns.c')
-rw-r--r--client/libacron/apps/acronc/async_dns.c65
1 files changed, 0 insertions, 65 deletions
diff --git a/client/libacron/apps/acronc/async_dns.c b/client/libacron/apps/acronc/async_dns.c
deleted file mode 100644
index 2e221cf..0000000
--- a/client/libacron/apps/acronc/async_dns.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Created by yuuta on 7/24/22.
- */
-
-#include "handler.h"
-#include "log.h"
-
-#include <uv.h>
-
-static uv_getaddrinfo_t resolv;
-
-static struct addrinfo *ai = NULL;
-static struct addrinfo *ai_current = NULL;
-static void (*cb)(int status,
- const struct addrinfo *,
- void (*on_connect_result)(bool)) = NULL;
-
-static void on_conn(bool res) {
- if (res) {
- uv_freeaddrinfo(ai);
- ai = NULL;
- ai_current = NULL;
- cb = NULL;
- return;
- }
- ai_current = ai_current->ai_next;
- if (!ai_current) {
- /* No more result available. */
- cb(1, NULL, NULL);
- uv_freeaddrinfo(ai);
- ai = NULL;
- ai_current = NULL;
- cb = NULL;
- return;
- }
- cb(0, ai_current, &on_conn);
-}
-
-static void on_resolv(uv_getaddrinfo_t *req, int status, struct addrinfo *res) {
- LOGDV("on_resolv(req = %p): status = %d, res = %p",
- req,
- status,
- res);
- if (status) {
- LOGEV("Cannot resolve host: %s", uv_strerror(status));
- cb(status, NULL, NULL);
- return;
- }
- ai = res;
- ai_current = res;
- cb(0, ai_current, &on_conn);
-}
-
-int a_dns(const char *host,
- uint16_t port,
- void (*c)(int status,
- const struct addrinfo *,
- void (*on_connect_result)(bool))) {
- int r;
- char service[6];
- snprintf(service, 6, "%u", port);
- cb = c;
- if ((r = uv_getaddrinfo(loop, &resolv, on_resolv, host, service, NULL))) return r;
- return 0;
-}