Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com
Subject: [PATCH 1/2] coio: make hints in coio_getaddrinfo optional
Date: Fri, 17 May 2019 18:21:23 +0300	[thread overview]
Message-ID: <324d46363de8cfa27620050be80f3a0d97dd050c.1558106383.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1558106383.git.v.shpilevoy@tarantool.org>

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.
---
 src/lib/core/coio_task.c | 12 ++++++++----
 test/unit/coio.cc        | 18 ++++++++++++++++++
 test/unit/coio.result    |  4 ++++
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/lib/core/coio_task.c b/src/lib/core/coio_task.c
index 61f376203..d8095eef3 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 d1e744508..a2439bf46 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, "getaddringo");
+	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 7d7477979..0373530b0 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 - getaddringo
+	*** test_getaddrinfo: done ***
-- 
2.20.1 (Apple Git-117)

  reply	other threads:[~2019-05-17 15:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17 15:21 [PATCH 0/2] netbox connect timeout assertion Vladislav Shpilevoy
2019-05-17 15:21 ` Vladislav Shpilevoy [this message]
2019-05-17 15:21 ` [PATCH 2/2] coio: fix getaddrinfo assertion on 0 timeout Vladislav Shpilevoy
2019-05-20 14:53 ` [PATCH 0/2] netbox connect timeout assertion Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=324d46363de8cfa27620050be80f3a0d97dd050c.1558106383.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH 1/2] coio: make hints in coio_getaddrinfo optional' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox