summaryrefslogtreecommitdiff
path: root/test/test_netdb.c
blob: 1921f71481577a8c2d032dc5e51b58ca4ca868e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#include <usual/netdb.h>

#include <usual/string.h>
#include <usual/socket.h>
#include <usual/time.h>

#include "test_common.h"

static int gotres;

static void cb_func(union sigval v)
{
	gotres++;
}

static void test_gai(void *p)
{
	int res;
	struct sigevent sev;
	struct gaicb req;
	struct gaicb *rlist[] = { &req };

	memset(&req, 0, sizeof(req));
	req.ar_name = "localhost";

	memset(&sev, 0, sizeof(sev));
	sev.sigev_notify = SIGEV_THREAD;
	sev.sigev_notify_function = cb_func;

	res = getaddrinfo_a(GAI_NOWAIT, rlist, 1, &sev);
	if (res == EAI_SYSTEM && errno == ENOSYS) {
		/* ok - no impl */
		goto end;
	} else {
		int_check(res, 0);
	}

	while (gai_error(&req) == EAI_INPROGRESS || gotres == 0)
		usleep(10000);

	int_check(gai_error(&req), 0);

	freeaddrinfo(req.ar_result);

	int_check(gotres, 1);
end:;
}

struct testcase_t netdb_tests[] = {
	{ "getaddrinfo_a", test_gai },
	END_OF_TESTCASES
};