Browse Source

Compile for OS-9 PowerPC and ARMv7 with CLANG. (#1896)

* Modification to compile for OS-9 PowerPC and ARMv7 with CLANG.
CMakeLists.txt also contains a fix for CLANG compiler (define for __FLOAT_WORD_ORDER missing).

Signed-off-by: Kei-Thomsen <thomsen@microsys.de>

* OS-9 Little Endian detection.

Signed-off-by: Kei-Thomsen <thomsen@microsys.de>
Kei Thomsen 5 years ago
parent
commit
610ede7cc9
3 changed files with 61 additions and 4 deletions
  1. 8 2
      CMakeLists.txt
  2. 4 0
      include/ua_config.h.in
  3. 49 2
      plugins/ua_network_tcp.c

+ 8 - 2
CMakeLists.txt

@@ -238,6 +238,10 @@ if(NOT WIN32)
     list(APPEND open62541_LIBRARIES socket)
     list(APPEND open62541_LIBRARIES c)
     list(APPEND open62541_LIBRARIES stdc++)
+  elseif(OS9)
+    list(APPEND open62541_LIBRARIES netdb)
+    list(APPEND open62541_LIBRARIES ndblib)
+    list(APPEND open62541_LIBRARIES socket)
   else()
     list(APPEND open62541_LIBRARIES m)
     if(UA_ENABLE_MULTITHREADING OR UA_BUILD_UNIT_TESTS)
@@ -314,8 +318,10 @@ if(NOT UA_COMPILE_AS_CXX AND (CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID
     if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release")
         add_definitions(-ffunction-sections -fdata-sections -fno-stack-protector -fno-unwind-tables
                         -fno-asynchronous-unwind-tables -fno-math-errno -fmerge-all-constants -fno-ident)
-        set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -s")
-        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
+        if(NOT OS9)
+            set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -s")
+            set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
+        endif()
         if(APPLE)
             set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-dead_strip")
             set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip")

+ 4 - 0
include/ua_config.h.in

@@ -281,6 +281,10 @@ extern "C" {
 # if defined(__LITTLEENDIAN__)
 #  define UA_LITTLE_ENDIAN 1
 # endif
+#elif defined(_OS9000) /* OS-9 */
+# if defined(_LIL_END)
+#  define UA_LITTLE_ENDIAN 1
+# endif
 #endif
 #ifndef UA_LITTLE_ENDIAN
 # define UA_LITTLE_ENDIAN 0

+ 49 - 2
plugins/ua_network_tcp.c

@@ -863,7 +863,31 @@ UA_StatusCode UA_ClientConnectionTCP_poll(UA_Client *client, void *data) {
         UA_UInt32 timeSinceStart =
                         (UA_UInt32) ((UA_Double) (UA_DateTime_nowMonotonic() - connStart)
                                         * UA_DATETIME_MSEC);
+#ifdef _OS9000
+        /* OS-9 can't use select for checking write sockets.
+         * Therefore, we need to use connect until success or failed
+         */
+        UA_UInt32 timeout_usec = (tcpConnection->timeout - timeSinceStart)
+                        * 1000;
+        int resultsize = 0;
+        do {
+            u_int32 time = 0x80000001;
+            signal_code sig;
+
+            timeout_usec -= 1000000/256;    // Sleep 1/256 second
+            if (timeout_usec < 0)
+                break;
 
+            _os_sleep(&time,&sig);
+            error = connect(clientsockfd, tcpConnection->server->ai_addr,
+                        WIN32_INT tcpConnection->server->ai_addrlen);
+            if ((error == -1 && errno__ == EISCONN) || (error == 0))
+                resultsize = 1;
+            if (error == -1 && errno__ != EALREADY && errno__ != EINPROGRESS)
+                break;
+        }
+        while(resultsize == 0);
+#else
         fd_set fdset;
         FD_ZERO(&fdset);
         UA_fd_set(clientsockfd, &fdset);
@@ -874,7 +898,7 @@ UA_StatusCode UA_ClientConnectionTCP_poll(UA_Client *client, void *data) {
 
         int resultsize = select((UA_Int32) (clientsockfd + 1), NULL, &fdset,
         NULL, &tmptv);
-
+#endif
         if (resultsize == 1) {
             /* Windows does not have any getsockopt equivalent and it is not needed there */
 #ifdef _WIN32
@@ -1128,6 +1152,29 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
             if(timeSinceStart > dtTimeout)
                 break;
 
+#ifdef _OS9000
+            /* OS-9 can't use select for checking write sockets.
+             * Therefore, we need to use connect until success or failed
+             */
+            UA_DateTime timeout_usec = (dtTimeout - timeSinceStart) / UA_DATETIME_USEC;
+            int resultsize = 0;
+            do {
+                u_int32 time = 0x80000001;
+                signal_code sig;
+
+                timeout_usec -= 1000000/256;    // Sleep 1/256 second
+                if (timeout_usec < 0)
+                    break;
+
+                _os_sleep(&time,&sig);
+                error = connect(clientsockfd, server->ai_addr, WIN32_INT server->ai_addrlen);
+                if ((error == -1 && errno__ == EISCONN) || (error == 0))
+                    resultsize = 1;
+                if (error == -1 && errno__ != EALREADY && errno__ != EINPROGRESS)
+                    break;
+            }
+            while(resultsize == 0);
+#else 
             fd_set fdset;
             FD_ZERO(&fdset);
             UA_fd_set(clientsockfd, &fdset);
@@ -1136,7 +1183,7 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
                                     (long int) (timeout_usec % 1000000)};
 
             int resultsize = select((UA_Int32)(clientsockfd + 1), NULL, &fdset, NULL, &tmptv);
-
+#endif
             if(resultsize == 1) {
 #ifdef _WIN32
                 /* Windows does not have any getsockopt equivalent and it is not