Skip to content
Snippets Groups Projects
Commit 9c4f1c8a authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy Committed by Vladimir Davydov
Browse files

coio: make hints in coio_getaddrinfo optional

According to the standard by Open Group, getaddrinfo() hints
argument is optional - it can be NULL. When it is NULL, hints
is assumed to have 0 in ai_flags, ai_socktype, and ai_protocol;
AF_UNSPEC in ai_family.

See The Open Group Base Specifications.
parent 632e3160
No related branches found
No related tags found
No related merge requests found
......@@ -378,12 +378,16 @@ coio_getaddrinfo(const char *host, const char *port,
*
* Based on the workaround in https://bugs.python.org/issue17269
*/
if (hints != NULL) {
#if defined(__APPLE__) && defined(AI_NUMERICSERV)
if (hints && (hints->ai_flags & AI_NUMERICSERV) &&
(port == NULL || (port[0]=='0' && port[1]=='\0'))) port = "00";
if ((hints->ai_flags & AI_NUMERICSERV) != 0 &&
(port == NULL || (port[0]=='0' && port[1]=='\0')))
port = "00";
#endif
/* Fill hinting information for use by connect(2) or bind(2). */
memcpy(&task->hints, hints, sizeof(task->hints));
memcpy(&task->hints, hints, sizeof(task->hints));
} else {
task->hints.ai_family = AF_UNSPEC;
}
/* make no difference between empty string and NULL for host */
if (host != NULL && *host) {
task->host = strdup(host);
......
......@@ -68,6 +68,22 @@ test_call_f(va_list ap)
return res;
}
static void
test_getaddrinfo(void)
{
header();
plan(1);
const char *host = "127.0.0.1";
const char *port = "3333";
struct addrinfo *i;
/* NULL hints should work. It is a standard. */
int rc = coio_getaddrinfo(host, port, NULL, &i, 1);
is(rc, 0, "getaddrinfo");
freeaddrinfo(i);
check_plan();
footer();
}
static int
main_f(va_list ap)
{
......@@ -86,6 +102,8 @@ main_f(va_list ap)
fiber_cancel(call_fiber);
fiber_join(call_fiber);
test_getaddrinfo();
ev_break(loop(), EVBREAK_ALL);
return 0;
}
......
......@@ -6,3 +6,7 @@
*** test_call_f ***
# call done with res 0
*** test_call_f: done ***
*** test_getaddrinfo ***
1..1
ok 1 - getaddrinfo
*** test_getaddrinfo: done ***
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment