You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2017/11/23 08:56:37 UTC

[6/7] qpid-proton git commit: PROTON-1644/PROTON-522: [Partial fix] Change port choosing mechanism for C++ tests - Detect FreeBSD and MacOS X

PROTON-1644/PROTON-522: [Partial fix] Change port choosing mechanism for C++ tests
- Detect FreeBSD and MacOS X


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

Branch: refs/heads/master
Commit: b6ad8a996faa34aeb8e475902a6f151c5476d45f
Parents: 43e49f6
Author: Andrew Stitcher <as...@apache.org>
Authored: Mon Nov 13 12:52:06 2017 -0500
Committer: Andrew Stitcher <as...@apache.org>
Committed: Thu Nov 23 03:50:41 2017 -0500

----------------------------------------------------------------------
 proton-c/bindings/cpp/src/test_port.hpp | 31 ++++++++++++++++++++++++++++
 proton-c/src/tests/test_port.h          |  6 +++++-
 2 files changed, 36 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b6ad8a99/proton-c/bindings/cpp/src/test_port.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/test_port.hpp b/proton-c/bindings/cpp/src/test_port.hpp
index eb94e84..5d2fada 100644
--- a/proton-c/bindings/cpp/src/test_port.hpp
+++ b/proton-c/bindings/cpp/src/test_port.hpp
@@ -59,6 +59,37 @@ class test_socket {
     void close_early()  { closesocket(sock_); } // Windows won't allow two sockets on a port
 };
 
+#elif defined(__APPLE__) || defined(__FreeBSD__)
+
+// BSD derivatives don't support the same SO_REUSEADDR semantics as Linux so
+// do the same thing as windows and hope for the best
+extern "C" {
+# include <sys/types.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <unistd.h>
+# include <netdb.h>
+}
+
+void check_err(int ret, const std::string& what) {
+    if (ret) throw std::runtime_error(what + ": " + std::strerror(errno));
+}
+
+class test_socket {
+  public:
+    int sock_;
+    test_socket() : sock_(socket(AF_INET, SOCK_STREAM, 0)) {
+        check_err(sock_ < 0, "socket");
+        int on = 1;
+        check_err(setsockopt(sock_, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)),
+                  "setsockop");
+    }
+    ~test_socket() { }
+    void close_early() {
+        close(sock_);
+    }
+};
+
 #else  /* POSIX */
 
 extern "C" {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b6ad8a99/proton-c/src/tests/test_port.h
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/test_port.h b/proton-c/src/tests/test_port.h
index 0569c44..959e597 100644
--- a/proton-c/src/tests/test_port.h
+++ b/proton-c/src/tests/test_port.h
@@ -106,7 +106,7 @@ test_port_t test_port(const char* host) {
   check_err(tp.sock < 0, "socket");
 #ifndef _WIN32
   int on = 1;
-  check_err(setsockopt(tp.sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)), "setsockopt");;;
+  check_err(setsockopt(tp.sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)), "setsockopt");
 #endif
   struct sockaddr_in addr = {0};
   addr.sin_family = AF_INET;    /* set the type of connection to TCP/IP */
@@ -122,6 +122,8 @@ test_port_t test_port(const char* host) {
   test_port_use_host(&tp, host);
 #ifdef _WIN32                   /* Windows doesn't support the twice-open socket trick */
   closesocket(tp.sock);
+#elif defined (__APPLE__) || defined(__FreeBSD__)
+  close(tp.sock);
 #endif
   return tp;
 }
@@ -129,6 +131,8 @@ test_port_t test_port(const char* host) {
 void test_port_close(test_port_t *tp) {
 #ifdef _WIN32
   WSACleanup();
+#elif defined (__APPLE__) || defined(__FreeBSD__)
+  // We already closed and have no other cleanup to do
 #else
   close(tp->sock);
 #endif


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