+ /* add mdns reply FD to kqueue */
+ EV_SET(&mevent, DNSServiceRefSockFD(sdRef), EVFILT_READ, EV_ADD, 0, 0, 0);
+ n = kevent(kq, &mevent, 1, NULL, 0, NULL);
+ if (n != 0) return 0;
+
+ /* add interrupt pipe to kqueue if interrupt is enabled */
+ if (interrupt_pipe_enabled != 0)
+ {
+ interrupt_pipe = pthread_getspecific(interrupt_pipe_key);
+ if (interrupt_pipe != NULL)
+ {
+ if (interrupt_pipe[0] >= 0)
+ {
+ EV_SET(&ievent, interrupt_pipe[0], EVFILT_READ, EV_ADD, 0, 0, (void *)name);
+ /* allow this to fail silently (should never happen, but it would only break interrupts */
+ n = kevent(kq, &ievent, 1, NULL, 0, NULL);
+ }
+ }
+ }
+
+ /*
+ * Get notification token
+ * we use a self-notification token to allow a caller
+ * to signal the thread doing this DNS query to quit.
+ */
+ notify_name = NULL;
+ notify_token = -1;
+
+ asprintf(¬ify_name, "self.thread.%lu", (unsigned long)pthread_self());
+ if (notify_name != NULL)
+ {
+ status = notify_register_plain(notify_name, ¬ify_token);
+ free(notify_name);
+ }