AC_CHECK_FUNCS(err errx warn warnx getprogname setprogname)
AC_CHECK_FUNCS(posix_memalign memalign valloc)
AC_CHECK_FUNCS(fls flsl flsll ffs ffsl ffsll)
+AC_SEARCH_LIBS(getaddrinfo_a, anl)
+AC_CHECK_FUNCS(getaddrinfo_a)
### Functions provided only on win32
AC_CHECK_FUNCS(localtime_r recvmsg sendmsg usleep)
### Functions used by libusual itself
OBJS = test_string.o test_crypto.o test_aatree.o test_heap.o \
test_common.o test_list.o tinytest.o test_cbtree.o \
test_utf8.o test_strpool.o test_pgutil.o test_regex.o \
- test_cxalloc.o test_bits.o test_base.o
+ test_cxalloc.o test_bits.o test_base.o test_netdb.o
-test-all: test
+test-all: regtest.compat
include ../Makefile
/BASENAME/s,^,//,
/DIRNAME/s,^,//,
/REGCOMP/s,^,//,
+/GETADDRINFO_A/s,^,//,
{ "strpool/", strpool_tests },
{ "pgutil/", pgutil_tests },
{ "regex/", regex_tests },
+ { "netdb/", netdb_tests },
END_OF_GROUPS
};
extern struct testcase_t cxalloc_tests[];
extern struct testcase_t bits_tests[];
extern struct testcase_t base_tests[];
+extern struct testcase_t netdb_tests[];
--- /dev/null
+
+#include <usual/netdb.h>
+
+#include <usual/string.h>
+
+#include "test_common.h"
+
+
+static void test_gai(void *p)
+{
+ int res;
+ struct sigevent sev;
+
+ memset(&sev, 0, sizeof(sev));
+
+ sev.sigev_notify = SIGEV_THREAD;
+
+ res = getaddrinfo_a(GAI_NOWAIT, NULL, 0, &sev);
+
+ int_check(res, 0);
+end:;
+}
+
+struct testcase_t netdb_tests[] = {
+ { "getaddrinfo_a", test_gai },
+ END_OF_TESTCASES
+};
+
--- /dev/null
+/*
+ * libusual - Utility library for C
+ *
+ * Copyright (c) 2010 Marko Kreen, Skype Technologies
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <usual/netdb.h>
+
+#ifndef HAVE_GETADDRINFO_A
+
+int getaddrinfo_a(int mode, struct gaicb *list[], int nitems, struct sigevent *sevp)
+{
+ struct gaicb *g;
+ int i, res;
+
+ if (nitems <= 0)
+ return 0;
+ if (mode != GAI_WAIT || mode != GAI_NOWAIT)
+ goto einval;
+
+ for (i = 0; i < nitems; i++) {
+ g = list[i];
+ res = getaddrinfo(g->ar_name, g->ar_service, g->ar_request, &g->ar_result);
+ g->_state = res;
+ }
+
+ if (!sevp || sevp->sigev_notify == SIGEV_NONE)
+ return 0;
+
+ if (sevp->sigev_notify == SIGEV_SIGNAL) {
+ raise(sevp->sigev_signo);
+ } else if (sevp->sigev_notify == SIGEV_THREAD) {
+ sigval_t sv;
+ sevp->sigev_notify_function(sv);
+ } else
+ goto einval;
+ return 0;
+einval:
+ errno = EINVAL;
+ return EAI_SYSTEM;
+}
+
+#endif
+
--- /dev/null
+/*
+ * libusual - Utility library for C
+ *
+ * Copyright (c) 2010 Marko Kreen, Skype Technologies
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/** @file
+ *
+ * DNS lookup.
+ */
+
+#ifndef _USUAL_NETDB_H_
+#define _USUAL_NETDB_H_
+
+#include <usual/signal.h>
+
+#include <netdb.h>
+
+#ifndef HAVE_GETADDRINFO_A
+
+/** Async execution */
+#ifndef GAI_WAIT
+#define GAI_WAIT 0
+#endif
+
+/** Synchronous execution */
+#ifndef GAI_NOWAIT
+#define GAI_NOWAIT 1
+#endif
+
+/* avoid name conflicts */
+#define gaicb usual_gaicb
+#define getaddrinfo_a(a,b,c,d) usual_getaddrinfo_a(a,b,c,d)
+
+/**
+ * Request data for getaddrinfo_a().
+ *
+ * Fields correspond to getaddrinfo() parameters.
+ */
+struct gaicb {
+ /** node name */
+ const char *ar_name;
+ /** service name */
+ const char *ar_service;
+ /** hints */
+ const struct addrinfo *ar_request;
+ /** result */
+ struct addrinfo *ar_result;
+ /* internal state */
+ int _state;
+};
+
+/**
+ * Compat: Async DNS lookup.
+ */
+int getaddrinfo_a(int mode, struct gaicb *list[], int nitems, struct sigevent *sevp);
+
+#endif /* HAVE_GETADDRINFO_A */
+
+#endif /* _USUAL_NETDB_H_ */
+