resolver: replace init's cleanup lambda with a member; lcov --list ignores inconsistent

gcov 15 marks the lambda as not hit while its lines are, which lcov 2
rejects.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Max Lv
2026-10-27 17:10:19 +08:00
co-authored by Claude
parent 5aa6f6f699
commit 436b99bec2
3 changed files with 12 additions and 7 deletions
+1
View File
@@ -139,6 +139,7 @@ if (ENABLE_COVERAGE)
--include ${PROJECT_SOURCE_DIR}/src/*
--ignore-errors mismatch,unused,empty,gcov,inconsistent
COMMAND ${LCOV_EXECUTABLE} --list ${PROJECT_BINARY_DIR}/coverage.info
--ignore-errors inconsistent
COMMAND ${GENHTML_EXECUTABLE} ${PROJECT_BINARY_DIR}/coverage.info
--ignore-errors inconsistent
--output-directory ${PROJECT_BINARY_DIR}/coverage-html
+10 -7
View File
@@ -40,14 +40,9 @@ Status Resolver::init(event::Loop &loop, const char *nameservers, bool ipv6_firs
ares_library_cleanup();
return fail(Errc::config);
}
auto abandon = [this] {
ares_destroy(channel_);
channel_ = nullptr;
ares_library_cleanup();
};
if (nameservers != nullptr && ares_set_servers_ports_csv(channel_, nameservers) != ARES_SUCCESS) {
LOGE("failed to set nameservers %s", nameservers);
abandon();
abandon_channel();
return fail(Errc::config);
}
loop_ = &loop;
@@ -56,12 +51,20 @@ Status Resolver::init(event::Loop &loop, const char *nameservers, bool ipv6_firs
w.owner = this;
}
if (Status opened = timer_.open(loop, *this); !opened) {
abandon();
abandon_channel();
return opened;
}
return {};
}
// Undo init() after the channel was created.
void Resolver::abandon_channel() noexcept
{
ares_destroy(channel_);
channel_ = nullptr;
ares_library_cleanup();
}
Status Resolver::resolve(const char *host, std::uint16_t port, const ResolveCallback &cb) noexcept
{
if (channel_ == nullptr) {
+1
View File
@@ -82,6 +82,7 @@ private:
static void sock_state(void *data, ares_socket_t s, int readable, int writable) noexcept;
static void on_host(void *arg, int status, int timeouts, hostent *he) noexcept;
void on_timer() noexcept;
void abandon_channel() noexcept;
void rearm() noexcept;
void finish(Query *q, int status) noexcept;
void on_closed_all() noexcept;