aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-28 23:29:35 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-28 23:29:35 -0800
commitd574649899a29ce7eb96485c0a4c606f14f87011 (patch)
tree0d6282c98fc458a4c24cc0b9f0f442bb2b958da3 /src/core
parent945dbef5e8eb060654aec33851937f1e3325913b (diff)
downloadnng-d574649899a29ce7eb96485c0a4c606f14f87011.tar.gz
nng-d574649899a29ce7eb96485c0a4c606f14f87011.tar.bz2
nng-d574649899a29ce7eb96485c0a4c606f14f87011.zip
resolver: use explicit resolver item provided by caller
This avoids the need to perform multiple allocations for dialing, eliminating additional potential failures. Cancellation is also made simpler and more perfectly robust.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/platform.h11
-rw-r--r--src/core/tcp.c10
-rw-r--r--src/core/thread.c2
-rw-r--r--src/core/url.c17
4 files changed, 33 insertions, 7 deletions
diff --git a/src/core/platform.h b/src/core/platform.h
index 8b7aabbc..47f90467 100644
--- a/src/core/platform.h
+++ b/src/core/platform.h
@@ -347,6 +347,17 @@ extern int nni_tcp_listener_set(
extern int nni_tcp_listener_get(
nni_tcp_listener *, const char *, void *, size_t *, nni_type);
+typedef struct nni_resolv_item {
+ int ri_family;
+ bool ri_passive;
+ const char *ri_host;
+ uint16_t ri_port;
+ nng_sockaddr *ri_sa; // where result will be written
+
+} nni_resolv_item;
+
+extern void nni_resolv(nni_resolv_item *, nni_aio *);
+
// nni_resolv_ip resolves a DNS host and service name asynchronously.
// The family should be one of NNG_AF_INET, NNG_AF_INET6, or NNG_AF_UNSPEC.
// The first two constrain the name to those families, while the third will
diff --git a/src/core/tcp.c b/src/core/tcp.c
index fd1c7e96..b0ed75fb 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -31,6 +31,7 @@ typedef struct {
nni_aio conaio; // platform connection aio
nni_list conaios;
nni_mtx mtx;
+ nni_resolv_item resolv;
} tcp_dialer;
static void
@@ -57,7 +58,14 @@ tcp_dial_start_next(tcp_dialer *d)
if (nni_list_empty(&d->conaios)) {
return;
}
- nni_resolv_ip(d->host, d->port, d->af, false, &d->sa, &d->resaio);
+ memset(&d->resolv, 0, sizeof(d->resolv));
+ d->resolv.ri_family = d->af;
+ d->resolv.ri_passive = false;
+ d->resolv.ri_host = d->host;
+ d->resolv.ri_port = d->port;
+ d->resolv.ri_sa = &d->sa;
+
+ nni_resolv(&d->resolv, &d->resaio);
}
static void
diff --git a/src/core/thread.c b/src/core/thread.c
index 6f50476a..15baab04 100644
--- a/src/core/thread.c
+++ b/src/core/thread.c
@@ -172,4 +172,4 @@ void
nni_thr_set_name(nni_thr *thr, const char *name)
{
nni_plat_thr_set_name(thr != NULL ? &thr->thr : NULL, name);
-} \ No newline at end of file
+}
diff --git a/src/core/url.c b/src/core/url.c
index 1b39f809..48c79037 100644
--- a/src/core/url.c
+++ b/src/core/url.c
@@ -678,10 +678,11 @@ nng_url_clone(nng_url **dstp, const nng_url *src)
int
nni_url_to_address(nng_sockaddr *sa, const nng_url *url)
{
- int af;
- nni_aio aio;
- const char *h;
- int rv;
+ int af;
+ nni_aio aio;
+ const char *h;
+ int rv;
+ nni_resolv_item ri;
// This assumes the scheme is one that uses TCP/IP addresses.
@@ -700,7 +701,13 @@ nni_url_to_address(nng_sockaddr *sa, const nng_url *url)
h = NULL;
}
- nni_resolv_ip(h, url->u_port, af, true, sa, &aio);
+ memset(&ri, 0, sizeof(ri));
+ ri.ri_family = af;
+ ri.ri_passive = true;
+ ri.ri_host = h;
+ ri.ri_port = url->u_port;
+ ri.ri_sa = sa;
+ nni_resolv(&ri, &aio);
nni_aio_wait(&aio);
rv = nni_aio_result(&aio);
nni_aio_fini(&aio);