123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- *
- * Copyright 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
- * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
- */
- #ifdef UA_ARCHITECTURE_WIN32
- #ifndef PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
- #define PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
- #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
- /* Backup definition of SLIST_ENTRY on mingw winnt.h */
- #ifdef SLIST_ENTRY
- # pragma push_macro("SLIST_ENTRY")
- # undef SLIST_ENTRY
- # define POP_SLIST_ENTRY
- #endif
- /* Thread-Local Storage
- * --------------------
- * Thread-local storage is not required by the main library functionality. It is
- * only used for some testing strategies. ``UA_THREAD_LOCAL`` is empty if the
- * feature is not available. */
- #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
- # define UA_THREAD_LOCAL _Thread_local /* C11 */
- #elif defined(__cplusplus) && __cplusplus > 199711L
- # define UA_THREAD_LOCAL thread_local /* C++11 */
- #elif defined(_MSC_VER)
- # define UA_THREAD_LOCAL __declspec(thread) /* MSVC extension */
- #else
- # define UA_THREAD_LOCAL
- #endif
- #include <stdlib.h>
- #if defined(_WIN32) && !defined(__clang__)
- # include <malloc.h>
- #endif
- #include <stdio.h>
- #include <errno.h>
- #include <winsock2.h>
- #include <ws2tcpip.h>
- #include <windows.h>
- #ifdef _MSC_VER
- # ifndef UNDER_CE
- # include <io.h> //access
- # define UA_access _access
- # endif
- #else
- # include <unistd.h> //access and tests
- # define UA_access access
- #endif
- #ifdef POP_SLIST_ENTRY
- # undef SLIST_ENTRY
- # undef POP_SLIST_ENTRY
- # pragma pop_macro("SLIST_ENTRY")
- #endif
- #define ssize_t int
- #define OPTVAL_TYPE char
- #ifndef UA_sleep_ms
- #define UA_sleep_ms(X) Sleep(X)
- #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 ms);
- #endif
- #define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
- #define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
- #ifdef UNDER_CE
- # define errno
- #endif
- // Windows does not support ansi colors
- // #define UA_ENABLE_LOG_COLORS
- #define UA_IPV6 1
- #define UA_SOCKET int
- #define UA_INVALID_SOCKET -1
- #define UA_ERRNO WSAGetLastError()
- #define UA_INTERRUPTED WSAEINTR
- #define UA_AGAIN WSAEWOULDBLOCK
- #define UA_EAGAIN EAGAIN
- #define UA_WOULDBLOCK WSAEWOULDBLOCK
- #define UA_ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK
- #define UA_getnameinfo getnameinfo
- #define UA_send send
- #define UA_recv recv
- #define UA_close closesocket
- #define UA_select select
- #define UA_shutdown shutdown
- #define UA_socket socket
- #define UA_bind bind
- #define UA_listen listen
- #define UA_accept accept
- #define UA_connect connect
- #define UA_getaddrinfo getaddrinfo
- #define UA_getsockopt getsockopt
- #define UA_setsockopt setsockopt
- #define UA_freeaddrinfo freeaddrinfo
- #define UA_gethostname gethostname
- #define UA_free free
- #define UA_malloc malloc
- #define UA_calloc calloc
- #define UA_realloc realloc
- #define UA_snprintf(source, size, string, ...) _snprintf_s(source, size, _TRUNCATE, string, __VA_ARGS__)
- #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
- char *errno_str = NULL; \
- FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
- NULL, WSAGetLastError(), \
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
- (LPSTR)&errno_str, 0, NULL); \
- LOG; \
- LocalFree(errno_str); \
- }
- #define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
- #include "../ua_architecture_functions.h"
- #endif /* PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_ */
- #endif /* UA_ARCHITECTURE_WIN32 */
|