From 83317bb2bf9ebe18b848aeb7bd9f6ad141bcaf8b Mon Sep 17 00:00:00 2001 From: Hiroki Noda Date: Sun, 17 Dec 2017 11:48:52 +0900 Subject: [PATCH] Call __res_init on linux when getaddrinfo failed, fix #40 --- dub.sdl | 2 +- source/eventcore/drivers/posix/dns.d | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/dub.sdl b/dub.sdl index 2835443..f8eb045 100644 --- a/dub.sdl +++ b/dub.sdl @@ -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" diff --git a/source/eventcore/drivers/posix/dns.d b/source/eventcore/drivers/posix/dns.d index babcf08..13452b9 100644 --- a/source/eventcore/drivers/posix/dns.d +++ b/source/eventcore/drivers/posix/dns.d @@ -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); } - -