-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS: New implementation of service publication #2786
macOS: New implementation of service publication #2786
Conversation
@cathyjf that's something I wanted to investigate in the future. Thank you for your PR, this great. Can you remove avahi from the Portfile too? |
b8c7f02
to
e96da6d
Compare
Done. I also removed a reference to it from the documentation. |
|
a24a713
to
2099407
Compare
Done.
I've now added a healthy additional amount of documentation.
The C++ Core Guidelines ("a collaborative effort led by Bjarne Stroustrup") state in section SF.22: "Use an unnamed (anonymous) namespace for all internal/non-exported entities". I agree with this guideline. The use of the anonymous namespace makes it clear that the items inside it are not part of the public interface of the file. Without using this idiom, it's hard to tell what is part of the interface and what is not. For example, for the GNU/Linux and Windows implementations of service publication, there are a ton of top-level functions, and it's not at all clear at a glance what is part of the interface and what is part of the implementation. In my new implementation, it's very clear, because everything is inside an anonymous namespace except for one function ( I agree with you that something similar could be achieved by naming the anonymous namespace something like |
0ed8b1d
to
69b1a35
Compare
Thank you for the updates and the explanation! |
e7c4cc8
to
5815c0b
Compare
I have fixed the lint error. |
5815c0b
to
cb92e34
Compare
I have now fixed the clang-format error, which unfortunately did not show up until after I fixed the cmake-lint error with the previous modification. That's why I didn't fix both at once. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2786 +/- ##
=========================================
+ Coverage 8.95% 8.98% +0.03%
=========================================
Files 95 95
Lines 17386 17304 -82
Branches 8268 8232 -36
=========================================
- Hits 1557 1555 -2
+ Misses 12964 12884 -80
Partials 2865 2865
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Last question, do you have any ideas on how to unit test this? |
I haven't got the time to actually code review, but running this branch locally I got the DNS working just fine with Android, Switch and QT clients, I'll do a proper code review later. |
It would be complicated to craft programmatic unit tests for this code. First, we would need to restructure the code so that where we currently directly call the macOS API functions ( After all that, we wouldn't really be able to test very much. We could write tests to verify that calling The goal of writing tests for code is laudable but this isn't really a piece of code where it makes sense in my opinion to write unit tests, because the unit testing would be quite a bit more complicated than the code being tested, but not actually test very much. |
cb92e34
to
1dfbfd9
Compare
This unit test failures are not related to this PR. I need to investigate what's going on. |
The current implementation of service publication on macOS uses `avahi-client`, but the majority of macOS machines do not have Avahi installed because macOS provides a native alternative (`mDNSresponder`), meaning that there is no reason to install Avahi. The current implementation also attempts to load the Avahi client libraries using `dlopen(3)`, which has a variety of restrictions on macOS, such as only being willing to load from certain directories. Depending on where the Avahi binaries are installed, they might not be loadable through the current invocation of `dlopen(3)`. Instead of using an Avahi client on macOS, it makes more sense to use the native macOS API for publishing services via `mDNSresponder`. This commit supplies such an implementation that uses the macOS native API. It also has the advantage of being much simpler than the previous implementation. Furthermore, this new implementation works on all macOS machines, because it relies only on native APIs, rather than on third-party software that is not commonly installed on macOS.
1dfbfd9
to
a555b15
Compare
The current implementation of service publication on macOS uses `avahi-client`, but the majority of macOS machines do not have Avahi installed because macOS provides a native alternative (`mDNSresponder`), meaning that there is no reason to install Avahi. The current implementation also attempts to load the Avahi client libraries using `dlopen(3)`, which has a variety of restrictions on macOS, such as only being willing to load from certain directories. Depending on where the Avahi binaries are installed, they might not be loadable through the current invocation of `dlopen(3)`. Instead of using an Avahi client on macOS, it makes more sense to use the native macOS API for publishing services via `mDNSresponder`. This commit supplies such an implementation that uses the macOS native API. It also has the advantage of being much simpler than the previous implementation. Furthermore, this new implementation works on all macOS machines, because it relies only on native APIs, rather than on third-party software that is not commonly installed on macOS.
The current implementation of service publication on macOS uses
avahi-client
, but the majority of macOS machines do not have Avahiinstalled because macOS provides a native alternative (
mDNSresponder
),meaning that there is no reason to install Avahi.
The current implementation also attempts to load the Avahi client
libraries using
dlopen(3)
, which has a variety of restrictions onmacOS, such as only being willing to load from certain directories.
Depending on where the Avahi binaries are installed, they might not
be loadable through the current invocation of
dlopen(3)
.Instead of using an Avahi client on macOS, it makes more sense to use
the native macOS API for publishing services via
mDNSresponder
. Thiscommit supplies such an implementation that uses the macOS native API.
It also has the advantage of being much simpler than the previous
implementation. Furthermore, this new implementation works on all
macOS machines, because it relies only on native APIs, rather than on
third-party software that is not commonly installed on macOS.
Type of Change
.github/...
)Checklist
Branch Updates
LizardByte requires that branches be up-to-date before merging. This means that after any PR is merged, this branch
must be updated before it can be merged. You must also
Allow edits from maintainers.