aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows/win_resolv.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-07-09 09:59:46 -0700
committerGarrett D'Amore <garrett@damore.org>2018-07-16 10:06:50 -0700
commitb44e20c80c936a29bfeaf964ec94bc62ac0386f5 (patch)
tree87b2b5b999046b7f10789d4bae863eeea9354e44 /src/platform/windows/win_resolv.c
parent05f404b917ddaf9fee70208a796cdf66ee747050 (diff)
downloadnng-b44e20c80c936a29bfeaf964ec94bc62ac0386f5.tar.gz
nng-b44e20c80c936a29bfeaf964ec94bc62ac0386f5.tar.bz2
nng-b44e20c80c936a29bfeaf964ec94bc62ac0386f5.zip
fixes #523 dialers could support multiple outstanding dial requests
fixes #179 DNS resolution should be done at connect time fixes #586 Windows IO completion port work could be better fixes #339 Windows iocp could use synchronous completions fixes #280 TCP abstraction improvements This is a rather monstrous set of changes, which refactors TCP, and the underlying Windows I/O completion path logic, in order to obtain a cleaner, simpler API, with support for asynchronous DNS lookups performed on connect rather than initialization time, the ability to have multiple connects or accepts pending, as well as fewer extraneous function calls. The Windows code also benefits from greatly reduced context switching, fewer lock operations performed, and a reduced number of system calls on the hot code path. (We use automatic event resetting instead of manual.) Some dead code was removed as well, and a few potential edge case leaks on failure paths (in the websocket code) were plugged. Note that all TCP based transports benefit from this work. The IPC code on Windows still uses the legacy IOCP for now, as does the UDP code (used for ZeroTier.) We will be converting those soon too.
Diffstat (limited to 'src/platform/windows/win_resolv.c')
-rw-r--r--src/platform/windows/win_resolv.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/platform/windows/win_resolv.c b/src/platform/windows/win_resolv.c
index fb9d6751..e2cd192e 100644
--- a/src/platform/windows/win_resolv.c
+++ b/src/platform/windows/win_resolv.c
@@ -69,7 +69,7 @@ resolv_cancel(nni_aio *aio, int rv)
}
static int
-resolv_gai_errno(int rv)
+resolv_errno(int rv)
{
switch (rv) {
case 0:
@@ -116,7 +116,7 @@ resolv_task(resolv_item *item)
hints.ai_family = item->family;
if ((rv = getaddrinfo(item->name, "80", &hints, &results)) != 0) {
- rv = resolv_gai_errno(rv);
+ rv = resolv_errno(rv);
goto done;
}
@@ -246,14 +246,14 @@ resolv_ip(const char *host, const char *serv, int passive, int family,
}
void
-nni_plat_tcp_resolv(
+nni_tcp_resolv(
const char *host, const char *serv, int family, int passive, nni_aio *aio)
{
resolv_ip(host, serv, passive, family, IPPROTO_TCP, aio);
}
void
-nni_plat_udp_resolv(
+nni_udp_resolv(
const char *host, const char *serv, int family, int passive, nni_aio *aio)
{
resolv_ip(host, serv, passive, family, IPPROTO_UDP, aio);
@@ -302,6 +302,47 @@ resolv_worker(void *notused)
}
int
+nni_ntop(const nni_sockaddr *sa, char *ipstr, char *portstr)
+{
+ void * ap;
+ uint16_t port;
+ int af;
+ switch (sa->s_family) {
+ case NNG_AF_INET:
+ ap = (void *) &sa->s_in.sa_addr;
+ port = sa->s_in.sa_port;
+ af = AF_INET;
+ break;
+ case NNG_AF_INET6:
+ ap = (void *) &sa->s_in6.sa_addr;
+ port = sa->s_in6.sa_port;
+ af = AF_INET6;
+ break;
+ default:
+ return (NNG_EINVAL);
+ }
+ if (ipstr != NULL) {
+ if (af == AF_INET6) {
+ size_t l;
+ ipstr[0] = '[';
+ InetNtopA(af, ap, ipstr + 1, INET6_ADDRSTRLEN);
+ l = strlen(ipstr);
+ ipstr[l++] = ']';
+ ipstr[l++] = '\0';
+ } else {
+ InetNtopA(af, ap, ipstr, INET6_ADDRSTRLEN);
+ }
+ }
+ if (portstr != NULL) {
+#ifdef NNG_LITTLE_ENDIAN
+ port = ((port >> 8) & 0xff) | ((port & 0xff) << 8);
+#endif
+ snprintf(portstr, 6, "%u", port);
+ }
+ return (0);
+}
+
+int
nni_win_resolv_sysinit(void)
{
nni_mtx_init(&resolv_mtx);