Skip to content

Commit

Permalink
Call __res_init on linux when getaddrinfo failed, fix vibe-d#40
Browse files Browse the repository at this point in the history
  • Loading branch information
kubo39 committed Dec 17, 2017
1 parent 979640b commit 2f406d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 8 additions & 3 deletions source/eventcore/drivers/posix/dns.d
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriver
hints.ai_flags = AI_ADDRCONFIG;
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); } ();
() @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);
}
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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();
}


Expand Down Expand Up @@ -337,5 +344,3 @@ private void passToDNSCallback()(DNSLookupID id, scope DNSLookupCallback cb, DNS
freeaddrinfo(ai_orig);
} catch (Exception e) assert(false, e.msg);
}


0 comments on commit 2f406d1

Please sign in to comment.