From e72b071057e18233455d6fd359034d0d39e5d0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?So=CC=88nke=20Ludwig?= Date: Mon, 23 Jan 2017 12:17:53 +0100 Subject: [PATCH] Add debug output for the getaddrinfo based DNS lookup driver. --- source/eventcore/drivers/posix.d | 9 ++++++++- tests/0-dns.d | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/source/eventcore/drivers/posix.d b/source/eventcore/drivers/posix.d index c56ff88..739a00f 100644 --- a/source/eventcore/drivers/posix.d +++ b/source/eventcore/drivers/posix.d @@ -923,6 +923,7 @@ final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriver override DNSLookupID lookupHost(string name, DNSLookupCallback on_lookup_finished) { + debug (EventCoreLogDNS) print("lookup %s", name); auto handle = getFreeHandle(); if (handle > m_maxHandle) m_maxHandle = handle; @@ -934,18 +935,21 @@ final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriver auto t = task!taskFun(l, AddressFamily.UNSPEC, events, m_event); try taskPool.put(t); catch (Exception e) return DNSLookupID.invalid; + debug (EventCoreLogDNS) print("lookup handle: %s", handle); return handle; } /// public static void taskFun(Lookup* lookup, int af, shared(Events) events, EventID event) { + debug (EventCoreLogDNS) print("lookup %s start", lookup.name); addrinfo hints; 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); } (); events.trigger(event, true); + debug (EventCoreLogDNS) print("lookup %s finished", lookup.name); } override void cancelLookup(DNSLookupID handle) @@ -956,11 +960,14 @@ final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriver private void onDNSSignal(EventID event) @trusted nothrow { + debug (EventCoreLogDNS) print("DNS event triggered"); + m_events.wait(m_event, &onDNSSignal); size_t lastmax; foreach (i, ref l; m_lookups) { if (i > m_maxHandle) break; if (l.callback) { if (l.result || l.retcode) { + debug (EventCoreLogDNS) print("found finished lookup %s for %s", i, l.name); auto cb = l.callback; auto ai = l.result; DNSStatus status; @@ -976,7 +983,7 @@ final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriver } else lastmax = i; } } - m_events.wait(m_event, &onDNSSignal); + debug (EventCoreLogDNS) print("Max active DNS handle: %s", m_maxHandle); } private DNSLookupID getFreeHandle() diff --git a/tests/0-dns.d b/tests/0-dns.d index 0aa02fb..08b5fe6 100644 --- a/tests/0-dns.d +++ b/tests/0-dns.d @@ -1,6 +1,7 @@ /++ dub.sdl: name "test" dependency "eventcore" path=".." + debugVersions "EventCoreLogDNS" +/ module test;