Closed svladykin closed 2 years ago
The diff looks horrible, but actually the change is this:
for (int i = 0; i < 2; i++) {
for (p = sinfo; p != NULL; p = p->ai_next) {
if (i == 0 ^ p->ai_family == family) {
continue;
}
Merging #87 (2d957b4) into master (871e848) will increase coverage by
0.00%
. The diff coverage is100.00%
.
@@ Coverage Diff @@
## master #87 +/- ##
=======================================
Coverage 99.81% 99.81%
=======================================
Files 21 21
Lines 2188 2192 +4
Branches 383 385 +2
=======================================
+ Hits 2184 2188 +4
Partials 4 4
Impacted Files | Coverage Δ | |
---|---|---|
socket/sc_sock.c | 100.00% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 871e848...2d957b4. Read the comment docs.
With Hide whitespace
enabled the diff looks better.
@svladykin Thanks, it perfectly makes sense.
Connecting in non-blocking mode
AF_INET6
socket withsc_sock_connect("localhost")
where both IPv4 and IPv6 addresses are assigned to "localhost" but the server listens on IPv6 only.It fails with
Connection refused
becausegetaddrinfo
looks for any available address withAF_UNSPEC
and wrongly picks IPv4. And since it is non-blocking mode it can not retry after the failure.This change makes
sc_sock_connect()
give more respect to the configured socket family: the first iteration we try to connect to addresses with the matching family, the second iteration we try to connect to the rest.