Skip to content

Commit

Permalink
Fixed OSX compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
breese committed Aug 30, 2019
1 parent 6b8743a commit f528396
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 38 deletions.
4 changes: 1 addition & 3 deletions cmake/FindDNSSD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ option(DNSSD_WITH_AVAHI "Check for Avahi" ON)
set(DNSSD_WITH_MDNSRESPONDER "" CACHE PATH "Check for mDNSResponder using build directory")

if (APPLE)
# Included in libSystem
set(DNSSD_FOUND TRUE)
# FIXME: Create library alias instead
find_package(mDNSResponder)

elseif(WIN32)
# FIXME
Expand Down
4 changes: 4 additions & 0 deletions cmake/FindmDNSResponder.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ find_library(mDNSResponder_LIBRARY
NAMES dns_sd
PATHS "${mDNSResponder_BUILD_DIR}"
PATH_SUFFIXES mDNSPosix/build/prod)
if (NOT mDNSResponder_LIBRARY)
find_library(mDNSResponder_LIBRARY
NAMES dns_services)
endif()

set(mDNSResponder_FOUND FALSE CACHE BOOL "" FORCE)
if (mDNSResponder_INCLUDE_DIR AND mDNSResponder_LIBRARY)
Expand Down
11 changes: 5 additions & 6 deletions src/dnssd/mdns/browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ struct browser::callback
const bool commit = !(flags & kDNSServiceFlagsMoreComing);
if (flags & kDNSServiceFlagsAdd)
{
self->listener.on_browser_appear(contact, commit);
self->member.listener.on_browser_appear(contact, commit);
}
else
{
self->listener.on_browser_disappear(contact, commit);
self->member.listener.on_browser_disappear(contact, commit);
}
}
else
{
self->listener.on_browser_failure(mdns::make_error_code(error));
self->member.listener.on_browser_failure(mdns::make_error_code(error));
}
}
catch (...)
Expand All @@ -79,8 +79,7 @@ struct browser::callback
browser::browser(const std::string& type,
mdns::handle& connection,
typename browser::listener& listener)
: connection(connection),
listener(listener)
: member{ connection, listener, {} }
{
const ::DNSServiceFlags flags = kDNSServiceFlagsShareConnection;
std::string regtype = mdns::type_encode(type);
Expand All @@ -98,7 +97,7 @@ browser::browser(const std::string& type,
this);
throw_on_error(error);

handle.reset(ref);
member.handle.reset(ref);
}

} // namespace mdns
Expand Down
10 changes: 6 additions & 4 deletions src/dnssd/mdns/browser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ class browser

private:
struct callback;

mdns::handle& connection;
browser::listener& listener;
mdns::handle handle;
struct
{
mdns::handle& connection;
browser::listener& listener;
mdns::handle handle;
} member;
};

} // namespace mdns
Expand Down
4 changes: 2 additions & 2 deletions src/dnssd/mdns/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace
class mdns_category : public boost::system::error_category
{
public:
const char *name() const BOOST_SYSTEM_NOEXCEPT
const char *name() const noexcept override
{
return "mDNSResponder";
}
std::string message(int value) const
std::string message(int value) const override
{
switch (DNSServiceErrorType(value))
{
Expand Down
33 changes: 15 additions & 18 deletions src/dnssd/mdns/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ struct resolver::callback
}
}

self->contact.index(to_index(interface_index));
self->contact.properties(properties);
self->member.contact.index(to_index(interface_index));
self->member.contact.properties(properties);
// FIXME: Set port directly on contact?
self->port = boost::asio::detail::socket_ops::network_to_host_short(port);
self->member.port = boost::asio::detail::socket_ops::network_to_host_short(port);
self->on_resolved(host);
}
else
{
self->listener.on_resolver_failure(mdns::make_error_code(error));
self->member.listener.on_resolver_failure(mdns::make_error_code(error));
}
}
catch (const boost::system::system_error& ex)
{
self->listener.on_resolver_failure(ex.code());
self->member.listener.on_resolver_failure(ex.code());
}
catch (...)
{
Expand All @@ -125,13 +125,13 @@ struct resolver::callback
if (error == kDNSServiceErr_NoError)
{
const bool more = flags & kDNSServiceFlagsMoreComing;
self->contact.address(mdns::to_address(*address));
self->contact.port(self->port);
self->member.contact.address(mdns::to_address(*address));
self->member.contact.port(self->member.port);
self->on_addrinfo(more);
}
else
{
self->listener.on_resolver_failure(mdns::make_error_code(error));
self->member.listener.on_resolver_failure(mdns::make_error_code(error));
}
}
catch (...)
Expand All @@ -148,10 +148,7 @@ struct resolver::callback
resolver::resolver(mdns::handle& connection,
const aware::contact& contact,
typename resolver::listener& listener)
: connection(connection),
listener(listener),
contact(contact),
port(0)
: member{ connection, listener, {}, contact, 0 }
{
const ::DNSServiceFlags flags = kDNSServiceFlagsShareConnection;
auto regtype = mdns::type_encode(contact.type());
Expand All @@ -167,34 +164,34 @@ resolver::resolver(mdns::handle& connection,
this);
throw_on_error(error);

handle.reset(ref);
member.handle.reset(ref);
}

void resolver::on_resolved(const char *host)
{
const ::DNSServiceFlags flags = kDNSServiceFlagsShareConnection;
const ::DNSServiceProtocol protocol = kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6;

auto ref = connection.get<DNSServiceRef>();
auto ref = member.connection.get<DNSServiceRef>();
::DNSServiceErrorType error = ::DNSServiceGetAddrInfo(&ref,
flags,
from_index(contact.index()),
from_index(member.contact.index()),
protocol,
host,
&resolver::callback::on_addrinfo,
this);
throw_on_error(error);

handle.reset(ref);
member.handle.reset(ref);
}

void resolver::on_addrinfo(bool more)
{
if (!more)
{
handle.reset();
member.handle.reset();
}
listener.on_resolver_done(contact);
member.listener.on_resolver_done(member.contact);
}

} // namespace mdns
Expand Down
13 changes: 8 additions & 5 deletions src/dnssd/mdns/resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ class resolver
private:
struct callback;

mdns::handle& connection;
resolver::listener& listener;
mdns::handle handle;
aware::contact contact;
unsigned short port;
struct
{
mdns::handle& connection;
resolver::listener& listener;
mdns::handle handle;
aware::contact contact;
unsigned short port;
} member;
};

} // namespace mdns
Expand Down

0 comments on commit f528396

Please sign in to comment.