clang-format

pull/641/head
Brad House 1 year ago
parent 45698509d8
commit 6e83c28ab4
  1. 4
      src/lib/ares__htable.c
  2. 31
      src/lib/ares__threads.c
  3. 3
      src/lib/ares_cancel.c
  4. 3
      src/lib/ares_fds.c
  5. 5
      src/lib/ares_getaddrinfo.c
  6. 3
      src/lib/ares_gethostbyaddr.c
  7. 3
      src/lib/ares_gethostbyname.c
  8. 11
      src/lib/ares_getnameinfo.c
  9. 9
      src/lib/ares_init.c
  10. 76
      src/lib/ares_private.h
  11. 3
      src/lib/ares_process.c
  12. 10
      src/lib/ares_qcache.c
  13. 3
      src/lib/ares_query.c
  14. 12
      src/lib/ares_search.c
  15. 3
      src/lib/ares_send.c
  16. 4
      src/lib/ares_timeout.c
  17. 44
      test/ares-test.h

@ -225,8 +225,8 @@ static ares_bool_t ares__htable_expand(ares__htable_t *htable)
/* Slow path, collisions */ /* Slow path, collisions */
while ((node = ares__llist_node_first(htable->buckets[i])) != NULL) { while ((node = ares__llist_node_first(htable->buckets[i])) != NULL) {
const void *val = ares__llist_node_val(node); const void *val = ares__llist_node_val(node);
size_t idx = HASH_IDX(htable, htable->bucket_key(val)); size_t idx = HASH_IDX(htable, htable->bucket_key(val));
/* Try fast path again as maybe we popped one collision off and the /* Try fast path again as maybe we popped one collision off and the
* next we can reuse the llist parent */ * next we can reuse the llist parent */

@ -37,8 +37,9 @@ struct ares__thread_mutex {
static ares__thread_mutex_t *ares__thread_mutex_create(void) static ares__thread_mutex_t *ares__thread_mutex_create(void)
{ {
ares__thread_mutex_t *mut = ares_malloc_zero(sizeof(*mut)); ares__thread_mutex_t *mut = ares_malloc_zero(sizeof(*mut));
if (mut == NULL) if (mut == NULL) {
return NULL; return NULL;
}
InitializeCriticalSection(&mut->mutex); InitializeCriticalSection(&mut->mutex);
return mut; return mut;
@ -46,28 +47,31 @@ static ares__thread_mutex_t *ares__thread_mutex_create(void)
static void ares__thread_mutex_destroy(ares__thread_mutex_t *mut) static void ares__thread_mutex_destroy(ares__thread_mutex_t *mut)
{ {
if (mut == NULL) if (mut == NULL) {
return; return;
}
DeleteCriticalSection(&mut->mutex); DeleteCriticalSection(&mut->mutex);
ares_free(mut); ares_free(mut);
} }
static void ares__thread_mutex_lock(ares__thread_mutex_t *mut) static void ares__thread_mutex_lock(ares__thread_mutex_t *mut)
{ {
if (mut == NULL) if (mut == NULL) {
return; return;
}
EnterCriticalSection(&mut->mutex); EnterCriticalSection(&mut->mutex);
} }
static void ares__thread_mutex_unlock(ares__thread_mutex_t *mut) static void ares__thread_mutex_unlock(ares__thread_mutex_t *mut)
{ {
if (mut == NULL) if (mut == NULL) {
return; return;
}
LeaveCriticalSection(&mut->mutex); LeaveCriticalSection(&mut->mutex);
} }
# else # else
# include <pthread.h> # include <pthread.h>
struct ares__thread_mutex { struct ares__thread_mutex {
pthread_mutex_t mutex; pthread_mutex_t mutex;
@ -77,8 +81,9 @@ static ares__thread_mutex_t *ares__thread_mutex_create(void)
{ {
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
ares__thread_mutex_t *mut = ares_malloc_zero(sizeof(*mut)); ares__thread_mutex_t *mut = ares_malloc_zero(sizeof(*mut));
if (mut == NULL) if (mut == NULL) {
return NULL; return NULL;
}
if (pthread_mutexattr_init(&attr) != 0) { if (pthread_mutexattr_init(&attr) != 0) {
ares_free(mut); ares_free(mut);
@ -104,32 +109,36 @@ fail:
static void ares__thread_mutex_destroy(ares__thread_mutex_t *mut) static void ares__thread_mutex_destroy(ares__thread_mutex_t *mut)
{ {
if (mut == NULL) if (mut == NULL) {
return; return;
}
pthread_mutex_destroy(&mut->mutex); pthread_mutex_destroy(&mut->mutex);
ares_free(mut); ares_free(mut);
} }
static void ares__thread_mutex_lock(ares__thread_mutex_t *mut) static void ares__thread_mutex_lock(ares__thread_mutex_t *mut)
{ {
if (mut == NULL) if (mut == NULL) {
return; return;
}
pthread_mutex_lock(&mut->mutex); pthread_mutex_lock(&mut->mutex);
} }
static void ares__thread_mutex_unlock(ares__thread_mutex_t *mut) static void ares__thread_mutex_unlock(ares__thread_mutex_t *mut)
{ {
if (mut == NULL) if (mut == NULL) {
return; return;
}
pthread_mutex_unlock(&mut->mutex); pthread_mutex_unlock(&mut->mutex);
} }
#endif # endif
ares_status_t ares__channel_threading_init(ares_channel_t *channel) ares_status_t ares__channel_threading_init(ares_channel_t *channel)
{ {
channel->lock = ares__thread_mutex_create(); channel->lock = ares__thread_mutex_create();
if (channel->lock == NULL) if (channel->lock == NULL) {
return ARES_ENOMEM; return ARES_ENOMEM;
}
return ARES_SUCCESS; return ARES_SUCCESS;
} }

@ -37,8 +37,9 @@
*/ */
void ares_cancel(ares_channel_t *channel) void ares_cancel(ares_channel_t *channel)
{ {
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);

@ -37,8 +37,9 @@ int ares_fds(ares_channel_t *channel, fd_set *read_fds, fd_set *write_fds)
/* Are there any active queries? */ /* Are there any active queries? */
size_t active_queries; size_t active_queries;
if (channel == NULL || read_fds == NULL || write_fds == NULL) if (channel == NULL || read_fds == NULL || write_fds == NULL) {
return 0; return 0;
}
ares__channel_lock(channel); ares__channel_lock(channel);

@ -673,8 +673,9 @@ void ares_getaddrinfo(ares_channel_t *channel, const char *name,
const struct ares_addrinfo_hints *hints, const struct ares_addrinfo_hints *hints,
ares_addrinfo_callback callback, void *arg) ares_addrinfo_callback callback, void *arg)
{ {
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);
ares_getaddrinfo_int(channel, name, service, hints, callback, arg); ares_getaddrinfo_int(channel, name, service, hints, callback, arg);
ares__channel_unlock(channel); ares__channel_unlock(channel);
@ -764,7 +765,7 @@ static ares_bool_t as_is_first(const struct host_query *hquery)
static ares_bool_t as_is_only(const struct host_query *hquery) static ares_bool_t as_is_only(const struct host_query *hquery)
{ {
size_t nname = ares_strlen(hquery->name); size_t nname = ares_strlen(hquery->name);
if(hquery->channel->flags & ARES_FLAG_NOSEARCH) { if (hquery->channel->flags & ARES_FLAG_NOSEARCH) {
return ARES_TRUE; return ARES_TRUE;
} }
if (hquery->name != NULL && nname && hquery->name[nname - 1] == '.') { if (hquery->name != NULL && nname && hquery->name[nname - 1] == '.') {

@ -114,8 +114,9 @@ static void ares_gethostbyaddr_int(ares_channel_t *channel, const void *addr,
void ares_gethostbyaddr(ares_channel_t *channel, const void *addr, int addrlen, void ares_gethostbyaddr(ares_channel_t *channel, const void *addr, int addrlen,
int family, ares_host_callback callback, void *arg) int family, ares_host_callback callback, void *arg)
{ {
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);
ares_gethostbyaddr_int(channel, addr, addrlen, family, callback, arg); ares_gethostbyaddr_int(channel, addr, addrlen, family, callback, arg);
ares__channel_unlock(channel); ares__channel_unlock(channel);

@ -266,8 +266,7 @@ done:
/* I really have no idea why this is exposed as a public function, but since /* I really have no idea why this is exposed as a public function, but since
* it is, we can't kill this legacy function. */ * it is, we can't kill this legacy function. */
static ares_status_t ares_gethostbyname_file_int(ares_channel_t *channel, static ares_status_t ares_gethostbyname_file_int(ares_channel_t *channel,
const char *name, const char *name, int family,
int family,
struct hostent **host) struct hostent **host)
{ {
const ares_hosts_entry_t *entry; const ares_hosts_entry_t *entry;

@ -86,10 +86,10 @@ static void append_scopeid(const struct sockaddr_in6 *addr6,
#endif #endif
STATIC_TESTABLE char *ares_striendstr(const char *s1, const char *s2); STATIC_TESTABLE char *ares_striendstr(const char *s1, const char *s2);
static void ares_getnameinfo_int(ares_channel_t *channel, static void ares_getnameinfo_int(ares_channel_t *channel,
const struct sockaddr *sa, const struct sockaddr *sa,
ares_socklen_t salen, int flags_int, ares_socklen_t salen, int flags_int,
ares_nameinfo_callback callback, void *arg) ares_nameinfo_callback callback, void *arg)
{ {
const struct sockaddr_in *addr = NULL; const struct sockaddr_in *addr = NULL;
const struct sockaddr_in6 *addr6 = NULL; const struct sockaddr_in6 *addr6 = NULL;
@ -190,8 +190,9 @@ void ares_getnameinfo(ares_channel_t *channel, const struct sockaddr *sa,
ares_socklen_t salen, int flags_int, ares_socklen_t salen, int flags_int,
ares_nameinfo_callback callback, void *arg) ares_nameinfo_callback callback, void *arg)
{ {
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);
ares_getnameinfo_int(channel, sa, salen, flags_int, callback, arg); ares_getnameinfo_int(channel, sa, salen, flags_int, callback, arg);

@ -507,8 +507,9 @@ done:
void ares_set_local_ip4(ares_channel_t *channel, unsigned int local_ip) void ares_set_local_ip4(ares_channel_t *channel, unsigned int local_ip)
{ {
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);
channel->local_ip4 = local_ip; channel->local_ip4 = local_ip;
ares__channel_unlock(channel); ares__channel_unlock(channel);
@ -517,8 +518,9 @@ void ares_set_local_ip4(ares_channel_t *channel, unsigned int local_ip)
/* local_ip6 should be 16 bytes in length */ /* local_ip6 should be 16 bytes in length */
void ares_set_local_ip6(ares_channel_t *channel, const unsigned char *local_ip6) void ares_set_local_ip6(ares_channel_t *channel, const unsigned char *local_ip6)
{ {
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);
memcpy(&channel->local_ip6, local_ip6, sizeof(channel->local_ip6)); memcpy(&channel->local_ip6, local_ip6, sizeof(channel->local_ip6));
ares__channel_unlock(channel); ares__channel_unlock(channel);
@ -527,8 +529,9 @@ void ares_set_local_ip6(ares_channel_t *channel, const unsigned char *local_ip6)
/* local_dev_name should be null terminated. */ /* local_dev_name should be null terminated. */
void ares_set_local_dev(ares_channel_t *channel, const char *local_dev_name) void ares_set_local_dev(ares_channel_t *channel, const char *local_dev_name)
{ {
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);
ares_strcpy(channel->local_dev_name, local_dev_name, ares_strcpy(channel->local_dev_name, local_dev_name,

@ -172,8 +172,8 @@ struct server_state {
* can be hard errors or timeouts * can be hard errors or timeouts
*/ */
struct ares_addr addr; struct ares_addr addr;
unsigned short udp_port; /* host byte order */ unsigned short udp_port; /* host byte order */
unsigned short tcp_port; /* host byte order */ unsigned short tcp_port; /* host byte order */
ares__llist_t *connections; ares__llist_t *connections;
struct server_connection *tcp_conn; struct server_connection *tcp_conn;
@ -254,59 +254,59 @@ typedef struct ares__thread_mutex ares__thread_mutex_t;
struct ares_channeldata { struct ares_channeldata {
/* Configuration data */ /* Configuration data */
unsigned int flags; unsigned int flags;
size_t timeout; /* in milliseconds */ size_t timeout; /* in milliseconds */
size_t tries; size_t tries;
size_t ndots; size_t ndots;
size_t maxtimeout; /* in milliseconds */ size_t maxtimeout; /* in milliseconds */
ares_bool_t rotate; ares_bool_t rotate;
unsigned short udp_port; /* stored in network order */ unsigned short udp_port; /* stored in network order */
unsigned short tcp_port; /* stored in network order */ unsigned short tcp_port; /* stored in network order */
int socket_send_buffer_size; /* setsockopt takes int */ int socket_send_buffer_size; /* setsockopt takes int */
int socket_receive_buffer_size; /* setsockopt takes int */ int socket_receive_buffer_size; /* setsockopt takes int */
char **domains; char **domains;
size_t ndomains; size_t ndomains;
struct apattern *sortlist; struct apattern *sortlist;
size_t nsort; size_t nsort;
char *lookups; char *lookups;
size_t ednspsz; size_t ednspsz;
unsigned int qcache_max_ttl; unsigned int qcache_max_ttl;
unsigned int optmask; unsigned int optmask;
/* For binding to local devices and/or IP addresses. Leave /* For binding to local devices and/or IP addresses. Leave
* them null/zero for no binding. * them null/zero for no binding.
*/ */
char local_dev_name[32]; char local_dev_name[32];
unsigned int local_ip4; unsigned int local_ip4;
unsigned char local_ip6[16]; unsigned char local_ip6[16];
/* Thread safety lock */ /* Thread safety lock */
ares__thread_mutex_t *lock; ares__thread_mutex_t *lock;
/* Server addresses and communications state. Sorted by least consecutive /* Server addresses and communications state. Sorted by least consecutive
* failures, followed by the configuration order if failures are equal. */ * failures, followed by the configuration order if failures are equal. */
ares__slist_t *servers; ares__slist_t *servers;
/* random state to use when generating new ids and generating retry penalties /* random state to use when generating new ids and generating retry penalties
*/ */
ares_rand_state *rand_state; ares_rand_state *rand_state;
/* All active queries in a single list */ /* All active queries in a single list */
ares__llist_t *all_queries; ares__llist_t *all_queries;
/* Queries bucketed by qid, for quickly dispatching DNS responses: */ /* Queries bucketed by qid, for quickly dispatching DNS responses: */
ares__htable_szvp_t *queries_by_qid; ares__htable_szvp_t *queries_by_qid;
/* Queries bucketed by timeout, for quickly handling timeouts: */ /* Queries bucketed by timeout, for quickly handling timeouts: */
ares__slist_t *queries_by_timeout; ares__slist_t *queries_by_timeout;
/* Map linked list node member for connection to file descriptor. We use /* Map linked list node member for connection to file descriptor. We use
* the node instead of the connection object itself so we can quickly look * the node instead of the connection object itself so we can quickly look
* up a connection and remove it if necessary (as otherwise we'd have to * up a connection and remove it if necessary (as otherwise we'd have to
* scan all connections) */ * scan all connections) */
ares__htable_asvp_t *connnode_by_socket; ares__htable_asvp_t *connnode_by_socket;
ares_sock_state_cb sock_state_cb; ares_sock_state_cb sock_state_cb;
void *sock_state_cb_data; void *sock_state_cb_data;
ares_sock_create_callback sock_create_cb; ares_sock_create_callback sock_create_cb;
void *sock_create_cb_data; void *sock_create_cb_data;
@ -574,19 +574,19 @@ ares_status_t ares__qcache_create(ares_rand_state *rand_state,
unsigned int max_ttl, unsigned int max_ttl,
ares__qcache_t **cache_out); ares__qcache_t **cache_out);
void ares__qcache_flush(ares__qcache_t *cache); void ares__qcache_flush(ares__qcache_t *cache);
ares_status_t ares_qcache_insert(ares_channel_t *channel, ares_status_t ares_qcache_insert(ares_channel_t *channel,
const struct timeval *now, const struct timeval *now,
const struct query *query, const struct query *query,
ares_dns_record_t *dnsrec); ares_dns_record_t *dnsrec);
ares_status_t ares_qcache_fetch(ares_channel_t *channel, ares_status_t ares_qcache_fetch(ares_channel_t *channel,
const struct timeval *now, const struct timeval *now,
const unsigned char *qbuf, size_t qlen, const unsigned char *qbuf, size_t qlen,
unsigned char **abuf, size_t *alen); unsigned char **abuf, size_t *alen);
ares_status_t ares__channel_threading_init(ares_channel_t *channel); ares_status_t ares__channel_threading_init(ares_channel_t *channel);
void ares__channel_threading_destroy(ares_channel_t *channel); void ares__channel_threading_destroy(ares_channel_t *channel);
void ares__channel_lock(ares_channel_t *channel); void ares__channel_lock(ares_channel_t *channel);
void ares__channel_unlock(ares_channel_t *channel); void ares__channel_unlock(ares_channel_t *channel);
#ifdef _MSC_VER #ifdef _MSC_VER
typedef __int64 ares_int64_t; typedef __int64 ares_int64_t;

@ -142,8 +142,9 @@ static void processfds(ares_channel_t *channel, fd_set *read_fds,
{ {
struct timeval now; struct timeval now;
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);

@ -127,7 +127,7 @@ fail:
return NULL; return NULL;
} }
static void ares__qcache_expire(ares__qcache_t *cache, static void ares__qcache_expire(ares__qcache_t *cache,
const struct timeval *now) const struct timeval *now)
{ {
ares__slist_node_t *node; ares__slist_node_t *node;
@ -421,16 +421,16 @@ done:
return status; return status;
} }
ares_status_t ares_qcache_insert(ares_channel_t *channel, ares_status_t ares_qcache_insert(ares_channel_t *channel,
const struct timeval *now, const struct timeval *now,
const struct query *query, const struct query *query,
ares_dns_record_t *dnsrec) ares_dns_record_t *dnsrec)
{ {
return ares__qcache_insert(channel->qcache, dnsrec, query->qbuf, query->qlen, return ares__qcache_insert(channel->qcache, dnsrec, query->qbuf, query->qlen,
now); now);
} }
ares_status_t ares_qcache_fetch(ares_channel_t *channel, ares_status_t ares_qcache_fetch(ares_channel_t *channel,
const struct timeval *now, const struct timeval *now,
const unsigned char *qbuf, size_t qlen, const unsigned char *qbuf, size_t qlen,
unsigned char **abuf, size_t *alen) unsigned char **abuf, size_t *alen)

@ -88,8 +88,9 @@ ares_status_t ares_query_qid(ares_channel_t *channel, const char *name,
void ares_query(ares_channel_t *channel, const char *name, int dnsclass, void ares_query(ares_channel_t *channel, const char *name, int dnsclass,
int type, ares_callback callback, void *arg) int type, ares_callback callback, void *arg)
{ {
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);
ares_query_qid(channel, name, dnsclass, type, callback, arg, NULL); ares_query_qid(channel, name, dnsclass, type, callback, arg, NULL);
ares__channel_unlock(channel); ares__channel_unlock(channel);

@ -57,8 +57,9 @@ static void search_callback(void *arg, int status, int timeouts,
static void end_squery(struct search_query *squery, ares_status_t status, static void end_squery(struct search_query *squery, ares_status_t status,
unsigned char *abuf, size_t alen); unsigned char *abuf, size_t alen);
static void ares_search_int(ares_channel_t *channel, const char *name, int dnsclass, static void ares_search_int(ares_channel_t *channel, const char *name,
int type, ares_callback callback, void *arg) int dnsclass, int type, ares_callback callback,
void *arg)
{ {
struct search_query *squery; struct search_query *squery;
char *s; char *s;
@ -157,11 +158,12 @@ static void ares_search_int(ares_channel_t *channel, const char *name, int dnscl
} }
} }
void ares_search(ares_channel_t *channel, const char *name, int dnsclass, void ares_search(ares_channel_t *channel, const char *name, int dnsclass,
int type, ares_callback callback, void *arg) int type, ares_callback callback, void *arg)
{ {
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);
ares_search_int(channel, name, dnsclass, type, callback, arg); ares_search_int(channel, name, dnsclass, type, callback, arg);
ares__channel_unlock(channel); ares__channel_unlock(channel);

@ -153,8 +153,9 @@ ares_status_t ares_send_ex(ares_channel_t *channel, const unsigned char *qbuf,
void ares_send(ares_channel_t *channel, const unsigned char *qbuf, int qlen, void ares_send(ares_channel_t *channel, const unsigned char *qbuf, int qlen,
ares_callback callback, void *arg) ares_callback callback, void *arg)
{ {
if (channel == NULL) if (channel == NULL) {
return; return;
}
ares__channel_lock(channel); ares__channel_lock(channel);

@ -47,8 +47,8 @@ static void remaining_time(struct timeval *remaining, const struct timeval *now,
remaining->tv_sec = tout->tv_sec - now->tv_sec; remaining->tv_sec = tout->tv_sec - now->tv_sec;
if (tout->tv_usec < now->tv_usec) { if (tout->tv_usec < now->tv_usec) {
remaining->tv_sec -= 1; remaining->tv_sec -= 1;
remaining->tv_usec = (tout->tv_usec + 1000000) - now->tv_usec; remaining->tv_usec = (tout->tv_usec + 1000000) - now->tv_usec;
} else { } else {
remaining->tv_usec = tout->tv_usec - now->tv_usec; remaining->tv_usec = tout->tv_usec - now->tv_usec;
} }

44
test/ares-test.h vendored

@ -67,9 +67,9 @@ extern std::vector<std::pair<int, bool>> families_modes;
// Process all pending work on ares-owned file descriptors, plus // Process all pending work on ares-owned file descriptors, plus
// optionally the given set-of-FDs + work function. // optionally the given set-of-FDs + work function.
void ProcessWork(ares_channel_t *channel, void ProcessWork(ares_channel_t *channel,
std::function<std::set<ares_socket_t>()> get_extrafds, std::function<std::set<ares_socket_t>()> get_extrafds,
std::function<void(ares_socket_t)> process_extra); std::function<void(ares_socket_t)> process_extra);
std::set<ares_socket_t> NoExtraFDs(); std::set<ares_socket_t> NoExtraFDs();
// Test fixture that ensures library initialization, and allows // Test fixture that ensures library initialization, and allows
@ -115,8 +115,8 @@ public:
/* Enable query cache for live tests */ /* Enable query cache for live tests */
struct ares_options opts; struct ares_options opts;
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.qcache_max_ttl = 300; opts.qcache_max_ttl = 300;
int optmask = ARES_OPT_QUERY_CACHE; int optmask = ARES_OPT_QUERY_CACHE;
EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask)); EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask));
EXPECT_NE(nullptr, channel_); EXPECT_NE(nullptr, channel_);
} }
@ -141,8 +141,8 @@ public:
{ {
struct ares_options opts; struct ares_options opts;
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.lookups = strdup("f"); opts.lookups = strdup("f");
int optmask = ARES_OPT_LOOKUPS; int optmask = ARES_OPT_LOOKUPS;
EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask)); EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask));
EXPECT_NE(nullptr, channel_); EXPECT_NE(nullptr, channel_);
free(opts.lookups); free(opts.lookups);
@ -170,8 +170,8 @@ public:
{ {
struct ares_options opts; struct ares_options opts;
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.lookups = strdup(GetParam().c_str()); opts.lookups = strdup(GetParam().c_str());
int optmask = ARES_OPT_LOOKUPS; int optmask = ARES_OPT_LOOKUPS;
EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask)); EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask));
EXPECT_NE(nullptr, channel_); EXPECT_NE(nullptr, channel_);
free(opts.lookups); free(opts.lookups);
@ -232,10 +232,10 @@ public:
std::set<ares_socket_t> fds() const; std::set<ares_socket_t> fds() const;
// Process activity on a file descriptor. // Process activity on a file descriptor.
void ProcessFD(ares_socket_t fd); void ProcessFD(ares_socket_t fd);
// Ports the server is responding to // Ports the server is responding to
unsigned short udpport() const unsigned short udpport() const
{ {
return udpport_; return udpport_;
} }
@ -246,19 +246,20 @@ public:
} }
private: private:
void ProcessRequest(ares_socket_t fd, struct sockaddr_storage *addr, ares_socklen_t addrlen, void ProcessRequest(ares_socket_t fd, struct sockaddr_storage *addr,
int qid, const std::string &name, int rrtype); ares_socklen_t addrlen, int qid, const std::string &name,
void ProcessPacket(ares_socket_t fd, struct sockaddr_storage *addr, ares_socklen_t addrlen, int rrtype);
byte *data, int len); void ProcessPacket(ares_socket_t fd, struct sockaddr_storage *addr,
ares_socklen_t addrlen, byte *data, int len);
unsigned short udpport_; unsigned short udpport_;
unsigned short tcpport_; unsigned short tcpport_;
ares_socket_t udpfd_; ares_socket_t udpfd_;
ares_socket_t tcpfd_; ares_socket_t tcpfd_;
std::set<ares_socket_t> connfds_; std::set<ares_socket_t> connfds_;
std::vector<byte> reply_; std::vector<byte> reply_;
int qid_; int qid_;
unsigned char *tcp_data_; unsigned char *tcp_data_;
size_t tcp_data_len_; size_t tcp_data_len_;
}; };
// Test fixture that uses a mock DNS server. // Test fixture that uses a mock DNS server.
@ -278,9 +279,10 @@ protected:
typedef std::vector<std::unique_ptr<NiceMockServer>> NiceMockServers; typedef std::vector<std::unique_ptr<NiceMockServer>> NiceMockServers;
std::set<ares_socket_t> fds() const; std::set<ares_socket_t> fds() const;
void ProcessFD(ares_socket_t fd); void ProcessFD(ares_socket_t fd);
static NiceMockServers BuildServers(int count, int family, unsigned short base_port); static NiceMockServers BuildServers(int count, int family,
unsigned short base_port);
NiceMockServers servers_; NiceMockServers servers_;
// Convenience reference to first server. // Convenience reference to first server.

Loading…
Cancel
Save