You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2016/11/25 21:01:24 UTC

[28/48] qpid-proton git commit: PROTON-1344: Fix proactor listen and broker examples for interop

PROTON-1344: Fix proactor listen and broker examples for interop

Added AI_PASSIVE to listener getaddrinfo() call, more correct and portable.

Example broker default host is "::" which listens for IPv6 and IPv4 on same port
on systems that allow that (IPV6ONLY defaults off)

Note that IPv4-only systems will need to say `libuv_broker -a localhost` but
since most modern systems support IPv6, that seems better than having clients
simply fail to connect depending on whether they use localhost or ::1.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/94bc2965
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/94bc2965
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/94bc2965

Branch: refs/heads/go1
Commit: 94bc2965a8a39b04f3d85b4aa1cfb287b2fc2144
Parents: ca45418
Author: Alan Conway <ac...@redhat.com>
Authored: Mon Nov 14 10:21:07 2016 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed Nov 16 19:52:38 2016 -0500

----------------------------------------------------------------------
 examples/c/proactor/broker.c         |  8 +++++---
 examples/c/proactor/libuv_proactor.c | 11 ++++++-----
 examples/c/proactor/receive.c        |  3 +--
 examples/c/proactor/send.c           |  3 +--
 4 files changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/94bc2965/examples/c/proactor/broker.c
----------------------------------------------------------------------
diff --git a/examples/c/proactor/broker.c b/examples/c/proactor/broker.c
index 79f34bc..e11a8bd 100644
--- a/examples/c/proactor/broker.c
+++ b/examples/c/proactor/broker.c
@@ -446,9 +446,11 @@ int main(int argc, char **argv) {
 
   /* Parse the URL or use default values */
   pn_url_t *url = urlstr ? pn_url_parse(urlstr) : NULL;
-  const char *host = url ? pn_url_get_host(url) : "localhost";
-  const char *port = url ? pn_url_get_port(url) : NULL;
-  if (!port) port = "amqp";
+  /* Listen on IPv6 wildcard. On systems that do not set IPV6ONLY by default,
+     this will also listen for mapped IPv4 on the same port.
+  */
+  const char *host = url ? pn_url_get_host(url) : "::";
+  const char *port = url ? pn_url_get_port(url) : "amqp";
 
   /* Initial broker_data value copied to each accepted connection */
   broker_data_t bd = { false };

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/94bc2965/examples/c/proactor/libuv_proactor.c
----------------------------------------------------------------------
diff --git a/examples/c/proactor/libuv_proactor.c b/examples/c/proactor/libuv_proactor.c
index ce5b948..8dd2706 100644
--- a/examples/c/proactor/libuv_proactor.c
+++ b/examples/c/proactor/libuv_proactor.c
@@ -425,11 +425,12 @@ static void on_accept(uv_stream_t* server, int err) {
   }
 }
 
-static int leader_resolve(psocket_t *ps, uv_getaddrinfo_t *info) {
+static int leader_resolve(psocket_t *ps, uv_getaddrinfo_t *info, bool server) {
   int err = leader_init(ps);
+  struct addrinfo hints = { 0 };
+  if (server) hints.ai_flags = AI_PASSIVE;
   if (!err) {
-    err = uv_getaddrinfo(&ps->proactor->loop, info, NULL,
-                         fixstr(ps->host), fixstr(ps->port), NULL);
+    err = uv_getaddrinfo(&ps->proactor->loop, info, NULL, fixstr(ps->host), fixstr(ps->port), &hints);
   }
   return err;
 }
@@ -437,7 +438,7 @@ static int leader_resolve(psocket_t *ps, uv_getaddrinfo_t *info) {
 static void leader_connect(psocket_t *ps) {
   pconn *pc = as_pconn(ps);
   uv_getaddrinfo_t info;
-  int err = leader_resolve(ps, &info);
+  int err = leader_resolve(ps, &info, false);
   if (!err) {
     err = uv_tcp_connect(&pc->connect, &pc->psocket.tcp, info.addrinfo->ai_addr, on_connect);
     uv_freeaddrinfo(info.addrinfo);
@@ -450,7 +451,7 @@ static void leader_connect(psocket_t *ps) {
 static void leader_listen(psocket_t *ps) {
   pn_listener_t *l = as_listener(ps);
   uv_getaddrinfo_t info;
-  int err = leader_resolve(ps, &info);
+  int err = leader_resolve(ps, &info, true);
   if (!err) {
     err = uv_tcp_bind(&l->psocket.tcp, info.addrinfo->ai_addr, 0);
     uv_freeaddrinfo(info.addrinfo);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/94bc2965/examples/c/proactor/receive.c
----------------------------------------------------------------------
diff --git a/examples/c/proactor/receive.c b/examples/c/proactor/receive.c
index 303e348..acdae0c 100644
--- a/examples/c/proactor/receive.c
+++ b/examples/c/proactor/receive.c
@@ -185,8 +185,7 @@ int main(int argc, char **argv) {
     /* Parse the URL or use default values */
     pn_url_t *url = urlstr ? pn_url_parse(urlstr) : NULL;
     const char *host = url ? pn_url_get_host(url) : NULL;
-    const char *port = url ? pn_url_get_port(url) : NULL;
-    if (!port) port = "amqp";
+    const char *port = url ? pn_url_get_port(url) : "amqp";
     strncpy(app.address, (url && pn_url_get_path(url)) ? pn_url_get_path(url) : "example", sizeof(app.address));
 
     /* Create the proactor and connect */

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/94bc2965/examples/c/proactor/send.c
----------------------------------------------------------------------
diff --git a/examples/c/proactor/send.c b/examples/c/proactor/send.c
index 68ba0c8..5d58895 100644
--- a/examples/c/proactor/send.c
+++ b/examples/c/proactor/send.c
@@ -187,8 +187,7 @@ int main(int argc, char **argv) {
     /* Parse the URL or use default values */
     pn_url_t *url = urlstr ? pn_url_parse(urlstr) : NULL;
     const char *host = url ? pn_url_get_host(url) : NULL;
-    const char *port = url ? pn_url_get_port(url) : NULL;
-    if (!port) port = "amqp";
+    const char *port = url ? pn_url_get_port(url) : "amqp";
     strncpy(app.address, (url && pn_url_get_path(url)) ? pn_url_get_path(url) : "example", sizeof(app.address));
 
     /* Create the proactor and connect */


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org