qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [43/50] [abbrv] qpid-proton git commit: PROTON-1495: c epoll use gai_strerror for getaddrinfo errors.
Date Fri, 09 Jun 2017 01:26:06 GMT
PROTON-1495: c epoll use gai_strerror for getaddrinfo errors.


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

Branch: refs/heads/go1
Commit: 8c5a031c23cac50b406a9d7f40b45ce44bd68a5d
Parents: 8ef841c
Author: Alan Conway <aconway@redhat.com>
Authored: Wed Jun 7 13:41:26 2017 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Wed Jun 7 13:44:48 2017 -0400

----------------------------------------------------------------------
 proton-c/src/proactor/epoll.c | 38 +++++++++++++++++++++++++-------------
 proton-c/src/proactor/libuv.c |  2 +-
 proton-c/src/tests/proactor.c | 16 +++++++++++++++-
 3 files changed, 41 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8c5a031c/proton-c/src/proactor/epoll.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/epoll.c b/proton-c/src/proactor/epoll.c
index 0bb0b10..69954d6 100644
--- a/proton-c/src/proactor/epoll.c
+++ b/proton-c/src/proactor/epoll.c
@@ -592,9 +592,7 @@ static pn_event_t *log_event(void* p, pn_event_t *e) {
   return e;
 }
 
-static void psocket_error(psocket_t *ps, int err, const char* what) {
-  strerrorbuf msg;
-  pstrerror(err, msg);
+static void psocket_error_str(psocket_t *ps, const char *msg, const char* what) {
   if (!ps->listener) {
     pn_connection_driver_t *driver = &psocket_pconnection(ps)->driver;
     pn_connection_driver_bind(driver); /* Bind so errors will be reported */
@@ -607,6 +605,16 @@ static void psocket_error(psocket_t *ps, int err, const char* what) {
   }
 }
 
+static void psocket_error(psocket_t *ps, int err, const char* what) {
+  strerrorbuf msg;
+  pstrerror(err, msg);
+  psocket_error_str(ps, msg, what);
+}
+
+static void psocket_gai_error(psocket_t *ps, int gai_err, const char* what) {
+  psocket_error_str(ps, gai_strerror(gai_err), what);
+}
+
 static void rearm(pn_proactor_t *p, epoll_extended_t *ee) {
   struct epoll_event ev;
   ev.data.ptr = ee;
@@ -991,7 +999,7 @@ static pn_event_batch_t *pconnection_process(pconnection_t *pc, uint32_t
events,
       else if (errno == EWOULDBLOCK)
         pc->read_blocked = true;
       else if (!(errno == EAGAIN || errno == EINTR)) {
-        psocket_error(&pc->psocket, errno, pc->disconnected ? "Disconnected" :
"on read from");
+        psocket_error(&pc->psocket, errno, pc->disconnected ? "disconnected" :
"on read from");
       }
     }
   }
@@ -1145,12 +1153,13 @@ void pn_proactor_connect(pn_proactor_t *p, pn_connection_t *c, const
char *addr)
   pn_connection_open(pc->driver.connection); /* Auto-open */
 
   bool notify = false;
-  if (!pgetaddrinfo(pc->psocket.host, pc->psocket.port, 0, &pc->addrinfo)) {
+  int gai_error = pgetaddrinfo(pc->psocket.host, pc->psocket.port, 0, &pc->addrinfo);
+  if (!gai_error) {
     pc->ai = pc->addrinfo;
     pconnection_maybe_connect_lh(pc); /* Start connection attempts */
     notify = pc->disconnected;
   } else {
-    psocket_error(&pc->psocket, errno, "connect to ");
+    psocket_gai_error(&pc->psocket, gai_error, "connect to ");
     notify = wake(&pc->context);
   }
   unlock(&pc->context.mutex);
@@ -1233,7 +1242,8 @@ void pn_proactor_listen(pn_proactor_t *p, pn_listener_t *l, const char
*addr, in
   pni_parse_addr(addr, addr_buf, PN_MAX_ADDR, &host, &port);
 
   struct addrinfo *addrinfo = NULL;
-  if (!pgetaddrinfo(host, port, AI_PASSIVE | AI_ALL, &addrinfo)) {
+  int gai_err = pgetaddrinfo(host, port, AI_PASSIVE | AI_ALL, &addrinfo);
+  if (!gai_err) {
     /* Count addresses, allocate enough space for sockets */
     size_t len = 0;
     for (struct addrinfo *ai = addrinfo; ai; ai = ai->ai_next) {
@@ -1273,10 +1283,13 @@ void pn_proactor_listen(pn_proactor_t *p, pn_listener_t *l, const
char *addr, in
   bool notify = wake(&l->context);
 
   if (l->psockets_size == 0) { /* All failed, create dummy socket with an error */
-    int err = errno;
     l->psockets = (psocket_t*)calloc(sizeof(psocket_t), 1);
     psocket_init(l->psockets, p, l, addr);
-    psocket_error(l->psockets, err, "listen on");
+    if (gai_err) {
+      psocket_gai_error(l->psockets, gai_err, "listen on");
+    } else {
+      psocket_error(l->psockets, errno, "listen on");
+    }
   }
   proactor_add(&l->context);
   unlock(&l->context.mutex);
@@ -1453,8 +1466,7 @@ void pn_listener_accept(pn_listener_t *l, pn_connection_t *c) {
   }
 
   if (err) {
-    /* Error on one socket closes the entire listener */
-    psocket_error(&l->psockets[0], errno, "listener state on accept");
+    psocket_error(&l->psockets[0], errno, "listener accepting from");
     unlock(&l->context.mutex);
     return;
   }
@@ -1464,8 +1476,8 @@ void pn_listener_accept(pn_listener_t *l, pn_connection_t *c) {
   int newfd = accept(ps->sockfd, NULL, 0);
   if (newfd < 0) {
     err = errno;
-    psocket_error(&pc->psocket, err, "failed initialization on accept");
-    psocket_error(ps, err, "accept");
+    psocket_error(&pc->psocket, err, "accepting from");
+    psocket_error(ps, err, "accepting from");
   } else {
     lock(&pc->context.mutex);
     configure_socket(newfd);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8c5a031c/proton-c/src/proactor/libuv.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/libuv.c b/proton-c/src/proactor/libuv.c
index cf3daab..146cd7a 100644
--- a/proton-c/src/proactor/libuv.c
+++ b/proton-c/src/proactor/libuv.c
@@ -601,7 +601,7 @@ static bool leader_connect(pconnection_t *pc) {
   int err = pconnection_init(pc);
   if (!err) err = leader_resolve(pc->work.proactor, &pc->addr, false);
   if (err) {
-    pconnection_error(pc, err, "connect resolving");
+    pconnection_error(pc, err, "on connect resolving");
     return true;
   } else {
     try_connect(pc);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8c5a031c/proton-c/src/tests/proactor.c
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/proactor.c b/proton-c/src/tests/proactor.c
index 19cc7f3..2764f79 100644
--- a/proton-c/src/tests/proactor.c
+++ b/proton-c/src/tests/proactor.c
@@ -493,7 +493,7 @@ static void test_errors(test_t *t) {
   pn_proactor_t *client = pts[0].proactor, *server = pts[1].proactor;
   test_port_t port = test_port(localhost);          /* Hold a port */
 
-  /* Invalid connect/listen parameters */
+  /* Invalid connect/listen service name */
   pn_connection_t *c = pn_connection();
   pn_proactor_connect(client, c, "127.0.0.1:xxx");
   TEST_ETYPE_EQUAL(t, PN_TRANSPORT_CLOSED, PROACTOR_TEST_RUN(pts));
@@ -507,6 +507,20 @@ static void test_errors(test_t *t) {
   TEST_STR_IN(t, "xxx", pn_condition_get_description(last_condition));
   TEST_ETYPE_EQUAL(t, PN_PROACTOR_INACTIVE, PROACTOR_TEST_RUN(pts));
 
+  /* Invalid connect/listen host name */
+  c = pn_connection();
+  pn_proactor_connect(client, c, "nosuch.example.com:");
+  TEST_ETYPE_EQUAL(t, PN_TRANSPORT_CLOSED, PROACTOR_TEST_RUN(pts));
+  TEST_STR_IN(t, "nosuch", pn_condition_get_description(last_condition));
+  TEST_ETYPE_EQUAL(t, PN_PROACTOR_INACTIVE, PROACTOR_TEST_RUN(pts));
+
+  l = pn_listener();
+  pn_proactor_listen(server, l, "nosuch.example.com:", 1);
+  TEST_ETYPE_EQUAL(t, PN_LISTENER_OPEN, PROACTOR_TEST_RUN(pts));
+  TEST_ETYPE_EQUAL(t, PN_LISTENER_CLOSE, PROACTOR_TEST_RUN(pts));
+  TEST_STR_IN(t, "nosuch", pn_condition_get_description(last_condition));
+  TEST_ETYPE_EQUAL(t, PN_PROACTOR_INACTIVE, PROACTOR_TEST_RUN(pts));
+
   /* Connect with no listener */
   c = pn_connection();
   pn_proactor_connect(client, c, port.host_port);


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


Mime
View raw message