ua_architecture.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  3. *
  4. * Copyright 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
  5. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  6. */
  7. #ifdef UA_ARCHITECTURE_POSIX
  8. #ifndef PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
  9. #define PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
  10. /* Enable POSIX features */
  11. #if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
  12. # define _XOPEN_SOURCE 600
  13. #endif
  14. #ifndef _DEFAULT_SOURCE
  15. # define _DEFAULT_SOURCE
  16. #endif
  17. /* On older systems we need to define _BSD_SOURCE.
  18. * _DEFAULT_SOURCE is an alias for that. */
  19. #ifndef _BSD_SOURCE
  20. # define _BSD_SOURCE
  21. #endif
  22. #include <errno.h>
  23. #include <arpa/inet.h>
  24. #include <netinet/in.h>
  25. #include <netdb.h>
  26. #include <sys/ioctl.h>
  27. #include <sys/select.h>
  28. #define UA_sleep_ms(X) usleep(X * 1000)
  29. #define OPTVAL_TYPE int
  30. #include <fcntl.h>
  31. #include <unistd.h> // read, write, close
  32. #ifdef __QNX__
  33. # include <sys/socket.h>
  34. #endif
  35. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  36. # include <sys/param.h>
  37. # if defined(BSD)
  38. # include<sys/socket.h>
  39. # endif
  40. #endif
  41. #if !defined(__CYGWIN__)
  42. # include <netinet/tcp.h>
  43. #endif
  44. /* Thread-Local Storage
  45. * --------------------
  46. * Thread-local storage is not required by the main library functionality. It is
  47. * only used for some testing strategies. ``UA_THREAD_LOCAL`` is empty if the
  48. * feature is not available. */
  49. #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
  50. # define UA_THREAD_LOCAL _Thread_local /* C11 */
  51. #elif defined(__cplusplus) && __cplusplus > 199711L
  52. # define UA_THREAD_LOCAL thread_local /* C++11 */
  53. #elif defined(__GNUC__)
  54. # define UA_THREAD_LOCAL __thread /* GNU extension */
  55. #else
  56. # define UA_THREAD_LOCAL
  57. #endif
  58. /* unsigned int for windows and workaround to a glibc bug */
  59. /* Additionally if GNU_LIBRARY is not defined, it may be using
  60. * musl libc (e.g. Docker Alpine) */
  61. #if defined(__OpenBSD__) || \
  62. (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
  63. (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
  64. !defined(__GNU_LIBRARY__))
  65. # define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
  66. # define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
  67. #else
  68. # define UA_fd_set(fd, fds) FD_SET(fd, fds)
  69. # define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
  70. #endif
  71. #define UA_access access
  72. #define UA_IPV6 1
  73. #define UA_SOCKET int
  74. #define UA_INVALID_SOCKET -1
  75. #define UA_ERRNO errno
  76. #define UA_INTERRUPTED EINTR
  77. #define UA_AGAIN EAGAIN
  78. #define UA_EAGAIN EAGAIN
  79. #define UA_WOULDBLOCK EWOULDBLOCK
  80. #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
  81. #define UA_ENABLE_LOG_COLORS
  82. #define UA_getnameinfo getnameinfo
  83. #define UA_send send
  84. #define UA_recv recv
  85. #define UA_close close
  86. #define UA_select select
  87. #define UA_shutdown shutdown
  88. #define UA_socket socket
  89. #define UA_bind bind
  90. #define UA_listen listen
  91. #define UA_accept accept
  92. #define UA_connect connect
  93. #define UA_getaddrinfo getaddrinfo
  94. #define UA_getsockopt getsockopt
  95. #define UA_setsockopt setsockopt
  96. #define UA_freeaddrinfo freeaddrinfo
  97. #define UA_gethostname gethostname
  98. #include <stdlib.h>
  99. #define UA_free free
  100. #define UA_malloc malloc
  101. #define UA_calloc calloc
  102. #define UA_realloc realloc
  103. #include <stdio.h>
  104. #define UA_snprintf snprintf
  105. #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
  106. char *errno_str = strerror(errno); \
  107. LOG; \
  108. }
  109. #define UA_LOG_SOCKET_ERRNO_GAI_WRAP(LOG) { \
  110. const char *errno_str = gai_strerror(errno); \
  111. LOG; \
  112. }
  113. #include "../ua_architecture_functions.h"
  114. #endif /* PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_ */
  115. #endif /* UA_ARCHITECTURE_POSIX */