Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protect the result
Browse files Browse the repository at this point in the history
atupone committed Jun 22, 2024
1 parent 4075c90 commit 47431eb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/net/AresHandler.cxx
Original file line number Diff line number Diff line change
@@ -16,8 +16,10 @@
/* system implementation headers */
#include <cerrno>
#include <cstring>
#include <mutex>

bool AresHandler::globallyInited = false;
std::mutex callback_mutex;

AresHandler::AresHandler(int _index)
: index(_index), status(None)
@@ -135,6 +137,9 @@ void AresHandler::callback(int callbackStatus, struct hostent *hostent)
{
if (callbackStatus == ARES_EDESTRUCTION)
return;

const std::lock_guard<std::mutex> lock(callback_mutex);

if (callbackStatus != ARES_SUCCESS)
{
logDebugMessage(1,"Player [%d] failed to resolve: error %d\n", index,
@@ -156,23 +161,27 @@ void AresHandler::callback(int callbackStatus, struct hostent *hostent)

const char *AresHandler::getHostname()
{
const std::lock_guard<std::mutex> lock(callback_mutex);

return hostName.c_str();
}

AresHandler::ResolutionStatus AresHandler::getHostAddress(struct in_addr
*clientAddr)
{
const std::lock_guard<std::mutex> lock(callback_mutex);

if (status == HbNSucceeded)
memcpy(clientAddr, &hostAddress, sizeof(hostAddress));
return status;
}

void AresHandler::setFd(fd_set *read_set, fd_set *write_set, int &maxFile)
void AresHandler::setFd(fd_set *, fd_set *, int &)
{
return;
}

void AresHandler::process(fd_set *read_set, fd_set *write_set)
void AresHandler::process(fd_set *, fd_set *)
{
return;
}

0 comments on commit 47431eb

Please sign in to comment.