Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C ares #354

Open
wants to merge 1 commit into
base: 2.4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/net/AresHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,7 +30,15 @@ AresHandler::AresHandler(int _index)
/* ask for local "hosts" lookups too */
static char lookups[] = "fb";
struct ares_options opts;
memset(&opts, 0, sizeof(opts));
int flags = 0;

opts.lookups = lookups;
flags |= ARES_OPT_LOOKUPS;
#if ARES_VERSION_MAJOR >= 1 && ARES_VERSION_MINOR >= 26
opts.evsys = ARES_EVSYS_DEFAULT;
flags |= ARES_OPT_EVENT_THREAD;
#endif

/* start up our resolver */
if (!globallyInited)
Expand All @@ -42,7 +52,7 @@ AresHandler::AresHandler(int _index)
}

/* start up our resolver */
int code = ares_init_options (&aresChannel, &opts, ARES_OPT_LOOKUPS);
int code = ares_init_options (&aresChannel, &opts, flags);
aresFailed = (code != ARES_SUCCESS);
if (aresFailed)
{
Expand Down Expand Up @@ -129,6 +139,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,
Expand All @@ -150,17 +163,29 @@ 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;
}

#if ARES_VERSION_MAJOR >= 1 && ARES_VERSION_MINOR >= 26
void AresHandler::setFd(fd_set *, fd_set *, int &)
{
}
void AresHandler::process(fd_set *, fd_set *)
{
}
#else
void AresHandler::setFd(fd_set *read_set, fd_set *write_set, int &maxFile)
{
if (aresFailed)
Expand All @@ -176,6 +201,7 @@ void AresHandler::process(fd_set *read_set, fd_set *write_set)
return;
ares_process(aresChannel, read_set, write_set);
}
#endif

// Local Variables: ***
// mode: C++ ***
Expand Down
Loading