qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [1/2] qpid-proton git commit: PROTON-1476: fix strict-aliasing errors on gcc 4.4.7
Date Thu, 11 May 2017 16:54:15 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 24a2ed321 -> 81ba5a3b3


PROTON-1476: fix strict-aliasing errors on gcc 4.4.7


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

Branch: refs/heads/master
Commit: beb38d21f430d421493188f70921c568668f51d1
Parents: 24a2ed3
Author: Alan Conway <aconway@redhat.com>
Authored: Thu May 11 09:05:49 2017 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Thu May 11 11:43:42 2017 -0400

----------------------------------------------------------------------
 proton-c/src/tests/test_tools.h | 57 ++++++++++++++----------------------
 1 file changed, 22 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/beb38d21/proton-c/src/tests/test_tools.h
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/test_tools.h b/proton-c/src/tests/test_tools.h
index ec656f6..04ae0f1 100644
--- a/proton-c/src/tests/test_tools.h
+++ b/proton-c/src/tests/test_tools.h
@@ -23,6 +23,7 @@
 #include <proton/type_compat.h>
 #include <proton/condition.h>
 #include <proton/event.h>
+#include <proton/proactor.h>
 
 #include <errno.h>
 #include <stdarg.h>
@@ -253,43 +254,13 @@ void sock_close(sock_t sock) { close(sock); }
 #endif
 
 
-/* Create a socket and bind(LOOPBACK:0) to get a free port.
-   Use SO_REUSEADDR so other processes can bind and listen on this port.
-   Close the returned fd when the other process is listening.
-   Asserts on error.
-*/
-sock_t sock_bind0(void) {
-  int sock =  socket(AF_INET, SOCK_STREAM, 0);
-  TEST_ASSERT_ERRNO(sock >= 0, errno);
-  int on = 1;
-  TEST_ASSERT_ERRNO(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on))
== 0, errno);
-  struct sockaddr_in addr = {0};
-  addr.sin_family = AF_INET;    /* set the type of connection to TCP/IP */
-  addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-  addr.sin_port = 0;            /* bind to port 0 */
-  TEST_ASSERT_ERRNO(bind(sock, (struct sockaddr*)&addr, sizeof(addr)) == 0, errno);
-  return sock;
-}
-
-int sock_port(sock_t sock) {
-  struct sockaddr addr = {0};
-  socklen_t len = sizeof(addr);
-  TEST_ASSERT_ERRNO(getsockname(sock, &addr, &len) == 0, errno);
-  int port = -1;
-  switch (addr.sa_family) {
-   case AF_INET: port = ((struct sockaddr_in*)&addr)->sin_port; break;
-   case AF_INET6: port = ((struct sockaddr_in6*)&addr)->sin6_port; break;
-   default: TEST_ASSERTF(false, "unknown protocol type %d\n", addr.sa_family); break;
-  }
-  return ntohs(port);
-}
 
 /* Combines a sock_t with the int and char* versions of the port for convenience */
 typedef struct test_port_t {
   sock_t sock;
   int port;                     /* port as integer */
-  char str[256];                /* port as string */
-  char host_port[256];          /* host:port string */
+  char str[PN_MAX_ADDR];	/* port as string */
+  char host_port[PN_MAX_ADDR];	/* host:port string */
 } test_port_t;
 
 /* Modifies tp->host_port to use host, returns the new tp->host_port */
@@ -298,11 +269,27 @@ const char *test_port_use_host(test_port_t *tp, const char *host) {
   return tp->host_port;
 }
 
-/* Create a test_port_t  */
+/* Create a socket and bind(INADDR_LOOPBACK:0) to get a free port.
+   Use SO_REUSEADDR so other processes can bind and listen on this port.
+   Use host to create the host_port address string.
+*/
 test_port_t test_port(const char* host) {
   test_port_t tp = {0};
-  tp.sock = sock_bind0();
-  tp.port = sock_port(tp.sock);
+  tp.sock = socket(AF_INET, SOCK_STREAM, 0);
+  TEST_ASSERT_ERRNO(tp.sock >= 0, errno);
+  int on = 1;
+  int err = setsockopt(tp.sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on));
+  TEST_ASSERT_ERRNO(!err, errno);
+  struct sockaddr_in addr = {0};
+  addr.sin_family = AF_INET;    /* set the type of connection to TCP/IP */
+  addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+  addr.sin_port = 0;            /* bind to port 0 */
+  err = bind(tp.sock, (struct sockaddr*)&addr, sizeof(addr));
+  TEST_ASSERT_ERRNO(!err, errno);
+  socklen_t len = sizeof(addr);
+  err = getsockname(tp.sock, (struct sockaddr*)&addr, &len); /* Get the bound port
*/
+  TEST_ASSERT_ERRNO(!err, errno);
+  tp.port = addr.sin_port;
   snprintf(tp.str, sizeof(tp.str), "%d", tp.port);
   test_port_use_host(&tp, host);
   return tp;


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


Mime
View raw message