Commit 1ff01c9b authored by Jason Madden's avatar Jason Madden

Add the definitions for ares_getaddrinfo.

parent adba05d0
......@@ -76,7 +76,9 @@ static void gevent_zero_prepare(struct ev_prepare* handle)
static void gevent_set_ev_alloc()
{
ev_set_allocator(gevent_realloc);
void* (*ptr)(void*, long);
ptr = (void*(*)(void*, long))&gevent_realloc;
ev_set_allocator(ptr);
}
#ifdef __clang__
......
#ifdef CARES_EMBED
#include "ares_setup.h"
#include "ares.h"
#else
#include <arpa/inet.h>
#define ares_inet_ntop(w,x,y,z) inet_ntop(w,x,y,z)
#endif
#ifdef CARES_EMBED
#include "ares_setup.h"
#include "ares_inet_net_pton.h"
#else
#include <arpa/inet.h>
#define ares_inet_pton(x,y,z) inet_pton(x,y,z)
#define ares_inet_net_pton(w,x,y,z) inet_net_pton(w,x,y,z)
#endif
......@@ -10,8 +10,6 @@
#include "ares.h"
#include "cares_ntop.h"
#include "cares_pton.h"
#if PY_MAJOR_VERSION >= 3
#define PY3K
......
cdef extern from "ares.h":
# These two are defined in <sys/socket.h> and <netdb.h>, respectively,
# on POSIX. On Windows, they are in <winsock2.h>. "ares.h" winds up
# indirectly including both of those.
struct sockaddr:
pass
struct hostent:
pass
struct ares_options:
int flags
void* sock_state_cb
......@@ -74,6 +82,7 @@ cdef extern from "ares.h":
int ARES_NI_LOOKUPHOST
int ARES_NI_LOOKUPSERVICE
ctypedef int ares_socklen_t
int ares_library_init(int flags)
void ares_library_cleanup()
......@@ -104,6 +113,46 @@ cdef extern from "ares.h":
int ares_set_servers(void* channel, ares_addr_node *servers)
struct ares_addrinfo_hints:
int ai_flags
int ai_family
int ai_socktype
int ai_protocol
struct ares_addrinfo_node:
int ai_ttl
int ai_flags
int ai_family
int ai_socktype
int ai_protocol
ares_socklen_t ai_addrlen
sockaddr *ai_addr
ares_addrinfo_node *ai_next
struct ares_addrinfo_cname:
int ttl
char *alias
char *name
ares_addrinfo_cname *next
struct ares_addrinfo:
ares_addrinfo_cname *cnames
ares_addrinfo_node *nodes
# typedef void (*ares_addrinfo_callback)(
# void *arg, int status,
# int timeouts,
# ares_addrinfo *result)
void ares_getaddrinfo(
void* channel,
const char *name,
const char* service,
const ares_addrinfo_hints *hints,
#ares_addrinfo_callback callback,
void* callback,
void *arg)
void ares_freeaddrinfo(ares_addrinfo *ai)
cdef extern from "cares_pton.h":
int ares_inet_pton(int af, char *src, void *dst)
int ares_inet_pton(int af, const char *src, void *dst)
......@@ -31,6 +31,7 @@ if getattr(resolver, 'pool', None) is not None:
from gevent.testing.sysinfo import RESOLVER_NOT_SYSTEM
from gevent.testing.sysinfo import RESOLVER_DNSPYTHON
from gevent.testing.sysinfo import RESOLVER_ARES
from gevent.testing.sysinfo import PY2
import gevent.testing.timing
......@@ -39,6 +40,7 @@ assert gevent_socket.gaierror is socket.gaierror
assert gevent_socket.error is socket.error
TRACE = not util.QUIET and os.getenv('GEVENT_DEBUG', '') == 'trace'
RUN_ALL_HOST_TESTS = os.getenv('GEVENTTEST_RUN_ALL_ETC_HOST_TESTS', '')
def trace(message, *args, **kwargs):
if TRACE:
......@@ -379,7 +381,17 @@ add(TestTypeError, 25)
class TestHostname(TestCase):
pass
def _normalize_result_gethostbyaddr(self, result):
result = TestCase._normalize_result_gethostbyaddr(self, result)
if RESOLVER_ARES and isinstance(result, tuple):
# The system resolver can return the FQDN, in the first result,
# when given certain configurations. But c-ares
# does not.
name = result[0]
name = name.split('.', 1)[0]
result = (name,) + result[1:]
return result
add(
TestHostname,
......@@ -504,7 +516,7 @@ class TestEtcHosts(TestCase):
hf = SanitizedHostsFile(os.path.join(os.path.dirname(__file__),
'hosts_file.txt'))
all_etc_hosts = sorted(hf.iter_all_host_addr_pairs())
if len(all_etc_hosts) > cls.MAX_HOSTS and util.QUIET:
if len(all_etc_hosts) > cls.MAX_HOSTS and not RUN_ALL_HOST_TESTS:
all_etc_hosts = all_etc_hosts[:cls.MAX_HOSTS]
for host, ip in all_etc_hosts:
......@@ -519,13 +531,14 @@ TestEtcHosts.populate_tests()
class TestGeventOrg(TestCase):
HOSTNAME = 'www.gevent.org'
HOSTNAME = 'python-gevent.readthedocs.org'
# For this test to work correctly, it needs to resolve to
# an address with a single A record; round-robin DNS and multiple A records
# may mess it up (subsequent requests---and we always make two---may return
# unequal results). We used to use gevent.org, but that now has multiple A records;
# trying www.gevent.org which is a CNAME to readthedocs.org.
# trying www.gevent.org which is a CNAME to readthedocs.org then worked, but it became
# an alias for python-gevent.readthedocs.org, which is an alias for readthedocs.io.
add(TestGeventOrg, TestGeventOrg.HOSTNAME)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment