8#ifdef UA_ARCHITECTURE_POSIX
10#ifndef PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
11#define PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
17#include <netinet/in.h>
20#include <sys/select.h>
28# define UA_sleep_ms(X) usleep(X * 1000)
31#define OPTVAL_TYPE int
37# include <sys/socket.h>
39#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
40# include <sys/param.h>
42# include<sys/socket.h>
46#include <netinet/tcp.h>
51#if defined(__OpenBSD__) || \
52 (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
53 (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
54 !defined(__GNU_LIBRARY__))
55# define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
56# define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
58# define UA_fd_set(fd, fds) FD_SET(fd, fds)
59# define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
62#define UA_access access
66#define UA_INVALID_SOCKET -1
68#define UA_INTERRUPTED EINTR
69#define UA_AGAIN EAGAIN
70#define UA_EAGAIN EAGAIN
71#define UA_WOULDBLOCK EWOULDBLOCK
72#define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
74#define UA_POLLIN POLLIN
75#define UA_POLLOUT POLLOUT
77#define UA_ENABLE_LOG_COLORS
80#define UA_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) \
81 getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
84#define UA_sendto sendto
85#define UA_recvfrom recvfrom
86#define UA_recvmsg recvmsg
90#define UA_select select
91#define UA_shutdown shutdown
92#define UA_socket socket
94#define UA_listen listen
95#define UA_accept accept
96#define UA_connect connect
97#define UA_getaddrinfo getaddrinfo
98#define UA_getsockopt getsockopt
99#define UA_setsockopt setsockopt
100#define UA_ioctl ioctl
101#define UA_freeaddrinfo freeaddrinfo
102#define UA_gethostname gethostname
103#define UA_getsockname getsockname
104#define UA_inet_pton inet_pton
106# define UA_if_nametoindex if_nametoindex
113# define UA_malloc malloc
114# define UA_calloc calloc
115# define UA_realloc realloc
120#define UA_snprintf snprintf
121#define UA_strncasecmp strncasecmp
123#define UA_clean_errno(STR_FUN) (errno == 0 ? (char*) "None" : (STR_FUN)(errno))
125#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
126 char *errno_str = UA_clean_errno(strerror); \
130#define UA_LOG_SOCKET_ERRNO_GAI_WRAP(LOG) { \
131 const char *errno_str = UA_clean_errno(gai_strerror); \
136#if UA_MULTITHREADING >= 100
141 pthread_mutex_t mutex;
142 pthread_mutexattr_t mutexAttr;
147UA_LOCK_INIT(UA_Lock *lock) {
148 pthread_mutexattr_init(&lock->mutexAttr);
149 pthread_mutexattr_settype(&lock->mutexAttr, PTHREAD_MUTEX_RECURSIVE);
150 pthread_mutex_init(&lock->mutex, &lock->mutexAttr);
151 lock->mutexCounter = 0;
155UA_LOCK_DESTROY(UA_Lock *lock) {
156 pthread_mutex_destroy(&lock->mutex);
157 pthread_mutexattr_destroy(&lock->mutexAttr);
161UA_LOCK(UA_Lock *lock) {
162 pthread_mutex_lock(&lock->mutex);
167UA_UNLOCK(UA_Lock *lock) {
169 pthread_mutex_unlock(&lock->mutex);
173UA_LOCK_ASSERT(UA_Lock *lock,
int num) {
177#define UA_EMPTY_STATEMENT \
180#define UA_LOCK_INIT(lock) UA_EMPTY_STATEMENT
181#define UA_LOCK_DESTROY(lock) UA_EMPTY_STATEMENT
182#define UA_LOCK(lock) UA_EMPTY_STATEMENT
183#define UA_UNLOCK(lock) UA_EMPTY_STATEMENT
184#define UA_LOCK_ASSERT(lock, num) UA_EMPTY_STATEMENT
189#if defined(__APPLE__) && defined(_SYS_QUEUE_H_)
194#undef SLIST_HEAD_INITIALIZER
201#undef SLIST_FOREACH_SAFE
203#undef SLIST_INSERT_AFTER
204#undef SLIST_INSERT_HEAD
205#undef SLIST_REMOVE_AFTER
206#undef SLIST_REMOVE_HEAD
209#undef LIST_HEAD_INITIALIZER
216#undef LIST_FOREACH_SAFE
218#undef LIST_INSERT_AFTER
219#undef LIST_INSERT_BEFORE
220#undef LIST_INSERT_HEAD
224#undef SIMPLEQ_HEAD_INITIALIZER
230#undef SIMPLEQ_FOREACH
231#undef SIMPLEQ_FOREACH_SAFE
233#undef SIMPLEQ_INSERT_HEAD
234#undef SIMPLEQ_INSERT_TAIL
235#undef SIMPLEQ_INSERT_AFTER
236#undef SIMPLEQ_REMOVE_HEAD
237#undef SIMPLEQ_REMOVE_AFTER
245#undef XSIMPLEQ_FOREACH
246#undef XSIMPLEQ_FOREACH_SAFE
248#undef XSIMPLEQ_INSERT_HEAD
249#undef XSIMPLEQ_INSERT_TAIL
250#undef XSIMPLEQ_INSERT_AFTER
251#undef XSIMPLEQ_REMOVE_HEAD
252#undef XSIMPLEQ_REMOVE_AFTER
254#undef TAILQ_HEAD_INITIALIZER
263#undef TAILQ_FOREACH_SAFE
264#undef TAILQ_FOREACH_REVERSE
265#undef TAILQ_FOREACH_REVERSE_SAFE
267#undef TAILQ_INSERT_HEAD
268#undef TAILQ_INSERT_TAIL
269#undef TAILQ_INSERT_AFTER
270#undef TAILQ_INSERT_BEFORE
274#undef CIRCLEQ_HEAD_INITIALIZER
282#undef CIRCLEQ_FOREACH
283#undef CIRCLEQ_FOREACH_SAFE
284#undef CIRCLEQ_FOREACH_REVERSE
285#undef CIRCLEQ_FOREACH_REVERSE_SAFE
287#undef CIRCLEQ_INSERT_AFTER
288#undef CIRCLEQ_INSERT_BEFORE
289#undef CIRCLEQ_INSERT_HEAD
290#undef CIRCLEQ_INSERT_TAIL
292#undef CIRCLEQ_REPLACE
#define UA_assert(ignore)
#define UA_sleep_ms(X)
This work is licensed under a Creative Commons CCZero 1.0 Universal License.