diff --git a/src/lib/core/coio_task.c b/src/lib/core/coio_task.c index 61f376203d11c78bc58460cbe5d39f684d8895a8..d8095eef3eabf8ec5d36b0eb753171725c3721f1 100644 --- a/src/lib/core/coio_task.c +++ b/src/lib/core/coio_task.c @@ -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); diff --git a/test/unit/coio.cc b/test/unit/coio.cc index d1e74450874bc93e164ad31fe3eefbc3eb69164f..5fb5a26d51c334e56261b009fb1e323c4c9e5110 100644 --- a/test/unit/coio.cc +++ b/test/unit/coio.cc @@ -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; } diff --git a/test/unit/coio.result b/test/unit/coio.result index 7d7477979702f34968ecb54788cd1f24f61053c9..5019fa48ab18c7efa896b11858b4a4f1e08400f5 100644 --- a/test/unit/coio.result +++ b/test/unit/coio.result @@ -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 ***