-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Problem: address parsing code is tied to the TCP code #3070
Conversation
a78f10b
to
003e2d1
Compare
On Debian 9 you can install the clang format tool by itself from stretch-backports:
And then pass |
@simias this is great work, thank you very much. |
With some versions of g++ also there's another error:
|
003e2d1
to
be214aa
Compare
@@ -83,6 +83,7 @@ src_libzmq_la_SOURCES = \ | |||
src/io_thread.hpp \ | |||
src/ip.cpp \ | |||
src/ip.hpp \ | |||
src/ip_resolver.cpp \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simias the header too
Ah, that's annoying. I "cheated" by putting the mock implementation in the C++ file in a bit extern "C" to avoid having to mess with how the autotools/cmake link the tests but I suppose that won't work if g++ is capricious. I guess I should put it in an external C file and do it right. |
Do you prefer that I keep squashing my single commit or do you prefer that I add additionals fixup commits for the time being? I'm not too used to code reviews on github so I don't know what's more convenient. |
Please squash them, given they are fixing the first commit Have you tried adding the |
be214aa
to
2beb27a
Compare
Do you think that'll work with all compilers? is __THROW standard? I assumed it was "dialectal" but I'm not exactly up to date with the latest C++ standards. |
Makefile.am
Outdated
unittests/unittest_mtrie | ||
unittests/unittest_mtrie \ | ||
unittests/unittest_ip_resolver \ | ||
unittests/unittest_ip_resolver_dns | ||
|
||
unittests_unittest_poller_SOURCES = unittests/unittest_poller.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simias for automake you also need an explicit section like these ones, just copy and paste
that's because each test is a program
4fefcbf
to
8733fd8
Compare
unittests/unittest_ip_resolver.cpp
Outdated
.expect_port (false) | ||
.ipv6 (false); | ||
|
||
assert (inet_pton (AF_INET, "1.2.128.129", &expected_addr) == 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will break Windows XP, you'll want a function that does something like:
#if defined(ZMQ_HAVE_WINDOWS) && (_WIN32_WINNT < 0x0600)
ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1");
#else
inet_pton (AF_INET, "127.0.0.1", &ip4addr.sin_addr);
#endif
Windows:
|
The system headers are already included by testutil.hpp with the appropriate ifdefs, add them there if there's extra ones needed |
bdedb45
to
b307da5
Compare
The appveyor job fell off the pr, not sure what happened, but it fails with a new error:
https://ci.appveyor.com/project/zeromq/libzmq/build/job/tw9mnlgjut7a07bk |
Various Linux builds from very old to very new and various architectures all look good: |
I'm not quite sure I understand the Windows build error there, is it a prototype mismatch or something else? I guess I should try to setup a Windows build environment and see for myself. |
From the looks of it, it would seem there is a prototype mismatch - I have no idea how this translates to, maybe @sigiesec can help:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb408409(v=vs.85).aspx |
There's a few more:
|
I can give the Windows build a look tomorrow morning. |
bcae93a
to
9dfa912
Compare
I've refactored the tests to have only one case per test and I've rewritten if_nametoindex to use the virtual interface trick. |
Great, looks good - except now windows has something else to complain about:
|
Just add
to unittest_ip_resolver.cpp This is also some issue with missing weak linking support. Probably this could be overcome more elegantly, but this is the solution that is currently used in some other tests. |
00066d8
to
68b3f96
Compare
Sorry for the multiple pushes, I messed up. |
Hopefully this is only a minor remaining issue, and the tests not only build but also run successfully under Windows :) If not, I can give it a closer look again. Apart from that: The PR looks really good to me now :) Great job, it's an important step in increasing unit test coverage in libzmq! |
They build now which is great, unfortunately there are a few test failures now :-/
Ditto - thanks for this great work |
Looks like the calls to getaddrinfo all fail for some reason. That's very odd. |
And it seems to work on Travis. Very strange indeed. Even test_resolve (resolver_opts, "1.2.128.129", "1.2.128.129"); My guess is either that I have some subtle memory corruption issue in the code that breaks the code or there's something different on Windows with regards to this API. At any rate I can't seem to reproduce it on Linux, even by tweaking the compilation flags. |
@simias I try running it on Windows on my local machine. |
@simias zmq::initialize_network must be called on Windows, see sigiesec@1595345 (this has quite a lot of changes since your file was not formatted with clang-format, but essentially only the calls to initialize_network and shutdown_network were added). Now, only 4 test cases fail, which seem to be related to ipv6 handling, first failure is https://ci.appveyor.com/project/sigiesec/libzmq/build/build-488/job/abgf6r84i26q2t3h#L1458 |
Ah, this is due to this piece of code: Maybe to get uniform behaviour, within the if block, the resulting address could be manually converted into a mapped IPV6 address? |
About that: "make clang-format-diff" does nothing on my machine for a reason I don't quite understand, it seemed suspicious given the amount of changes I've made but I thought I was just very lucky. I should've known better:
Regarding the new test error it seems to be that windows returns an AF_INET instead of an embedded IPV6 when asked to parse a numeric IPv4 IP:
|
Ah, good catch. I was trying to figure out what was wrong with address mapping on Windows, I should've read the code. I guess I will tweak the testing code to work in this scenario. |
About clang, the CI doesn't show anything either, so not sure what's going on? |
Looks like window's getaddrinfo accepts brackets around IPv6 when Linux doesn't. Oh well. I'll just remove that test then, it's useless. |
Solution: Factor the code into a different file with a well defined API and add unit tests.
Since clang-format still refuses to do its job on my end I fear you'll have to do it yourself (or let me know how to fix it). |
Actually I could tweak the parsing code so that brackets are accepted on Linux as well. I just need to add a copy of the bracket stripping code after the scope parsing code. This way you won't have the issue of some URLs being accepted on windows but not on linux. I can make a PR for that later if you want. |
Hm, this should probably produce an error instead.
Yes, as I wrote in my comment before this is explicitly done on Windows at this point: |
Yeah I read the comment when I was porting the code but I didn't realize that meant that the code would behave differently. Anyway, only one build fails on appveyor now and it seems unrelated to my patch. Is this a known problem or did I break something? https://ci.appveyor.com/project/zeromq/libzmq/build/build-2249/job/uaei3wy47y8p7ai7
|
@simias test_immediate and test_many_sockets are unfortunately failing for quite some time, this is not related to your changes! |
From my point of view, this is now ready to merge. |
LGTM! @simias thanks again. Given the amount of changes, please send another PR with 2 commits: one to add yourself to AUTHORS, and another one with a relicensing grant, see https://github.com/zeromq/libzmq/tree/master/RELICENSE for details |
Solution: Factor the code into a different file with a well defined API and add
unit tests.
My Debian doesn't have a recent-enough
clang-format
to runmake clang-format-check
so apologies in advance if I messed up the coding style here and there (which is almost certain given the size of the patch).I've attempted to match the previous implementation perfectly, including the arguable "quirks" such as the ones I've reported in #3069 (and a few others that I'm not sure about, such as specifying a %scope for an IPv4 address).
This is a pretty huge patch so I tried to be very comprehensive in the unit tests. I think the only path of the code that's not tested is when specifying an interface name as a bind point since the implementations to find the IP address associated with a network interface vary wildly from platform to platform so it's not trivial to come up with generic test code. I've tested manually that it still worked on Linux at least and I haven't made significant modifications to the architecture-specific code so I have good hopes that I haven't irremediably broken it.