Call __res_init on linux when getaddrinfo failed, fix #40

This commit is contained in:
Hiroki Noda 2017-12-17 11:48:52 +09:00
parent 979640b074
commit 83317bb2bf
2 changed files with 8 additions and 3 deletions

View file

@ -5,7 +5,7 @@ copyright "Copyright © 2012-2016 rejectedsoftware e.K."
targetType "library"
libs "anl" platform="linux"
libs "anl" "resolv" platform="linux"
libs "ws2_32" "user32" platform="windows-dmd"
dependency "taggedalgebraic" version="~>0.10.4"

View file

@ -83,6 +83,8 @@ final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriver
version (linx) hints.ai_flags |= AI_V4MAPPED;
hints.ai_family = af;
() @trusted { lookup.retcode = getaddrinfo(lookup.name.toStringz(), null, af == AddressFamily.UNSPEC ? null : &hints, &lookup.result); } ();
if (lookup.retcode == -1)
version (CRuntime_Glibc) version (linux) __res_init();
events.trigger(event, true);
debug (EventCoreLogDNS) print("lookup %s finished", lookup.name);
}
@ -177,7 +179,10 @@ final class EventDriverDNS_GAIA(Events : EventDriverEvents, Signals : EventDrive
auto ret = () @trusted { return getaddrinfo_a(GAI_NOWAIT, &res, 1, &evt); } ();
if (ret != 0)
{
version (CRuntime_Glibc) version (linux) __res_init();
return DNSLookupID.invalid;
}
m_lookups[handle].callback = on_lookup_finished;
m_events.loop.m_waiterCount++;
@ -240,6 +245,8 @@ version (linux) extern(C) {
int getaddrinfo_a(int mode, gaicb** list, int nitems, sigevent *sevp);
int gai_error(gaicb *req);
int gai_cancel(gaicb *req);
int __res_init();
}
@ -337,5 +344,3 @@ private void passToDNSCallback()(DNSLookupID id, scope DNSLookupCallback cb, DNS
freeaddrinfo(ai_orig);
} catch (Exception e) assert(false, e.msg);
}