DNSLookup: copy hostname and port instead of accessing member

This commit is contained in:
Benjamin Sergeant 2019-01-06 18:17:12 -08:00
parent 6deaa03114
commit 121acdab6f
2 changed files with 4 additions and 4 deletions

View File

@ -105,7 +105,7 @@ namespace ix
// Good resource on thread forced termination // Good resource on thread forced termination
// https://www.bo-yang.net/2017/11/19/cpp-kill-detached-thread // https://www.bo-yang.net/2017/11/19/cpp-kill-detached-thread
// //
_thread = std::thread(&DNSLookup::run, this); _thread = std::thread(&DNSLookup::run, this, _hostname, _port);
_thread.detach(); _thread.detach();
std::unique_lock<std::mutex> lock(_conditionVariableMutex); std::unique_lock<std::mutex> lock(_conditionVariableMutex);
@ -138,11 +138,11 @@ namespace ix
return _res; return _res;
} }
void DNSLookup::run() void DNSLookup::run(const std::string& hostname, int port) // thread runner
{ {
uint64_t id = _id; uint64_t id = _id;
std::string errMsg; std::string errMsg;
_res = getAddrInfo(_hostname, _port, errMsg); _res = getAddrInfo(hostname, port, errMsg);
// if this isn't an active job, and the control thread is gone // if this isn't an active job, and the control thread is gone
// there is not thing to do, and we don't want to touch the defunct // there is not thing to do, and we don't want to touch the defunct

View File

@ -43,7 +43,7 @@ namespace ix
int port, int port,
std::string& errMsg); std::string& errMsg);
void run(); // thread runner void run(const std::string& hostname, int port); // thread runner
std::string _hostname; std::string _hostname;
int _port; int _port;