Skip to content

Commit 9149e8a

Browse files
author
Clarkok Zhang
committed
Fix android getaddrinfo issue
1 parent 4b2b851 commit 9149e8a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

httplib.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3813,18 +3813,22 @@ inline int getaddrinfo_with_timeout(const char *node, const char *service,
38133813
std::condition_variable result_cv;
38143814
bool completed = false;
38153815
int result = EAI_SYSTEM;
3816-
std::string node = node;
3817-
std::string service = service;
3818-
struct addrinfo hints = hints;
3816+
std::string node;
3817+
std::string service;
3818+
struct addrinfo hints;
38193819
struct addrinfo *info = nullptr;
38203820
};
38213821

38223822
// Allocate on the heap, so the resolver thread can keep using the data.
38233823
auto state = std::make_shared<GetAddrInfoState>();
3824-
3825-
std::thread resolve_thread([=]() {
3826-
auto thread_result = getaddrinfo(
3827-
state->node.c_str(), state->service.c_str(), hints, &state->info);
3824+
state->node = node;
3825+
state->service = service;
3826+
state->hints = *hints;
3827+
3828+
std::thread resolve_thread([state]() {
3829+
auto thread_result =
3830+
getaddrinfo(state->node.c_str(), state->service.c_str(), &state->hints,
3831+
&state->info);
38283832

38293833
std::lock_guard<std::mutex> lock(state->mutex);
38303834
state->result = thread_result;

0 commit comments

Comments
 (0)