|
@@ -8,33 +8,8 @@
|
|
|
* Copyright 2017 (c) Thomas Stalder, Blue Time Concept SA
|
|
|
*/
|
|
|
|
|
|
-/* Enable POSIX features */
|
|
|
-#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
|
|
|
-# define _XOPEN_SOURCE 600
|
|
|
-#endif
|
|
|
-#ifndef _DEFAULT_SOURCE
|
|
|
-# define _DEFAULT_SOURCE
|
|
|
-#endif
|
|
|
-/* On older systems we need to define _BSD_SOURCE.
|
|
|
- * _DEFAULT_SOURCE is an alias for that. */
|
|
|
-#ifndef _BSD_SOURCE
|
|
|
-# define _BSD_SOURCE
|
|
|
-#endif
|
|
|
|
|
|
-/* Disable some security warnings on MSVC */
|
|
|
-#ifdef _MSC_VER
|
|
|
-# define _CRT_SECURE_NO_WARNINGS
|
|
|
-#endif
|
|
|
-
|
|
|
-/* Assume that Windows versions are newer than Windows XP */
|
|
|
-#if defined(__MINGW32__) && (!defined(WINVER) || WINVER < 0x501)
|
|
|
-# undef WINVER
|
|
|
-# undef _WIN32_WINDOWS
|
|
|
-# undef _WIN32_WINNT
|
|
|
-# define WINVER 0x0501
|
|
|
-# define _WIN32_WINDOWS 0x0501
|
|
|
-# define _WIN32_WINNT 0x0501
|
|
|
-#endif
|
|
|
+#include <ua_architecture.h>
|
|
|
|
|
|
#include "ua_network_tcp.h"
|
|
|
#include "ua_log_stdout.h"
|
|
@@ -43,135 +18,6 @@
|
|
|
#include <stdio.h> // snprintf
|
|
|
#include <string.h> // memset
|
|
|
|
|
|
-#if !defined(UA_FREERTOS)
|
|
|
-# include <errno.h>
|
|
|
-#else
|
|
|
-# define AI_PASSIVE 0x01
|
|
|
-# define TRUE 1
|
|
|
-# define FALSE 0
|
|
|
-# define ioctl ioctlsocket
|
|
|
-#endif
|
|
|
-
|
|
|
-#ifdef _WIN32
|
|
|
-# include <winsock2.h>
|
|
|
-# include <ws2tcpip.h>
|
|
|
-# define CLOSESOCKET(S) closesocket((SOCKET)S)
|
|
|
-# define ssize_t int
|
|
|
-# define WIN32_INT (int)
|
|
|
-# define OPTVAL_TYPE char
|
|
|
-# define ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK
|
|
|
-#else /* _WIN32 */
|
|
|
-# if defined(UA_FREERTOS)
|
|
|
-# define UA_FREERTOS_HOSTNAME "10.200.4.114"
|
|
|
-static inline int gethostname_freertos(char* name, size_t len){
|
|
|
- if(strlen(UA_FREERTOS_HOSTNAME) > (len))
|
|
|
- return -1;
|
|
|
- strcpy(name, UA_FREERTOS_HOSTNAME);
|
|
|
- return 0;
|
|
|
-}
|
|
|
-#define gethostname gethostname_freertos
|
|
|
-# include <lwip/tcpip.h>
|
|
|
-# include <lwip/netdb.h>
|
|
|
-# define CLOSESOCKET(S) lwip_close(S)
|
|
|
-# define sockaddr_storage sockaddr
|
|
|
-# ifdef BYTE_ORDER
|
|
|
-# undef BYTE_ORDER
|
|
|
-# endif
|
|
|
-# else /* Not freeRTOS */
|
|
|
-# define CLOSESOCKET(S) close(S)
|
|
|
-# include <arpa/inet.h>
|
|
|
-# include <netinet/in.h>
|
|
|
-# include <netdb.h>
|
|
|
-# include <sys/ioctl.h>
|
|
|
-# if defined(_WRS_KERNEL)
|
|
|
-# include <hostLib.h>
|
|
|
-# include <selectLib.h>
|
|
|
-# else /* defined(_WRS_KERNEL) */
|
|
|
-# include <sys/select.h>
|
|
|
-# endif /* defined(_WRS_KERNEL) */
|
|
|
-# endif /* Not freeRTOS */
|
|
|
-
|
|
|
-# define SOCKET int
|
|
|
-# define WIN32_INT
|
|
|
-# define OPTVAL_TYPE int
|
|
|
-# define ERR_CONNECTION_PROGRESS EINPROGRESS
|
|
|
-
|
|
|
-
|
|
|
-# include <fcntl.h>
|
|
|
-# include <unistd.h> // read, write, close
|
|
|
-
|
|
|
-# ifdef __QNX__
|
|
|
-# include <sys/socket.h>
|
|
|
-# endif
|
|
|
-# if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
|
-# include <sys/param.h>
|
|
|
-# if defined(BSD)
|
|
|
-# include<sys/socket.h>
|
|
|
-# endif
|
|
|
-# endif
|
|
|
-# if !defined(__CYGWIN__) && !defined(UA_FREERTOS)
|
|
|
-# include <netinet/tcp.h>
|
|
|
-# endif
|
|
|
-#endif /* _WIN32 */
|
|
|
-
|
|
|
-#ifndef UA_sleep_ms
|
|
|
-# ifdef _WIN32
|
|
|
-# define UA_sleep_ms(X) Sleep(X)
|
|
|
-# else /* _WIN32 */
|
|
|
-# if defined(UA_FREERTOS)
|
|
|
-# define UA_sleep_ms(X) vTaskDelay(pdMS_TO_TICKS(X))
|
|
|
-# else /* Not freeRTOS */
|
|
|
-# if defined(_WRS_KERNEL)
|
|
|
-# include <hostLib.h>
|
|
|
-# include <selectLib.h>
|
|
|
-# define UA_sleep_ms(X) \
|
|
|
- { \
|
|
|
- struct timespec timeToSleep; \
|
|
|
- timeToSleep.tv_sec = X / 1000; \
|
|
|
- timeToSleep.tv_nsec = 1000000 * (X % 1000); \
|
|
|
- nanosleep(&timeToSleep, NULL); \
|
|
|
- }
|
|
|
-# else /* defined(_WRS_KERNEL) */
|
|
|
-# define UA_sleep_ms(X) usleep(X * 1000)
|
|
|
-# endif /* defined(_WRS_KERNEL) */
|
|
|
-# endif /* Not freeRTOS */
|
|
|
-# endif /* _WIN32 */
|
|
|
-#else /* UA_sleep_ms */
|
|
|
-/* With this one can define its own UA_sleep_ms using a preprocessor define.
|
|
|
-E.g. see unit tests. */
|
|
|
-void UA_sleep_ms(size_t);
|
|
|
-#endif
|
|
|
-
|
|
|
-/* unsigned int for windows and workaround to a glibc bug */
|
|
|
-/* Additionally if GNU_LIBRARY is not defined, it may be using
|
|
|
- * musl libc (e.g. Docker Alpine) */
|
|
|
-#if defined(_WIN32) || defined(__OpenBSD__) || \
|
|
|
- (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
|
|
|
- (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
|
|
|
- !defined(__GNU_LIBRARY__))
|
|
|
-# define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
|
|
|
-# define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
|
|
|
-#else
|
|
|
-# define UA_fd_set(fd, fds) FD_SET(fd, fds)
|
|
|
-# define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
|
|
|
-#endif
|
|
|
-
|
|
|
-#ifdef UNDER_CE
|
|
|
-# define errno WSAGetLastError()
|
|
|
-#endif
|
|
|
-
|
|
|
-#ifdef _WIN32
|
|
|
-# define errno__ WSAGetLastError()
|
|
|
-# define INTERRUPTED WSAEINTR
|
|
|
-# define WOULDBLOCK WSAEWOULDBLOCK
|
|
|
-# define AGAIN WSAEWOULDBLOCK
|
|
|
-#else
|
|
|
-# define errno__ errno
|
|
|
-# define INTERRUPTED EINTR
|
|
|
-# define WOULDBLOCK EWOULDBLOCK
|
|
|
-# define AGAIN EAGAIN
|
|
|
-#endif
|
|
|
-
|
|
|
#include "ua_log_socket_error.h"
|
|
|
|
|
|
/****************************/
|