Line data Source code
1 : // Copyright (c) 2009-2010 Satoshi Nakamoto 2 : // Copyright (c) 2009-2014 The Bitcoin developers 3 : // Copyright (c) 2017-2021 The PIVX Core developers 4 : // Distributed under the MIT/X11 software license, see the accompanying 5 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 6 : 7 : #ifndef PIVX_COMPAT_H 8 : #define PIVX_COMPAT_H 9 : 10 : #if defined(HAVE_CONFIG_H) 11 : #include "config/pivx-config.h" 12 : #endif 13 : 14 : #ifdef WIN32 15 : #ifdef _WIN32_WINNT 16 : #undef _WIN32_WINNT 17 : #endif 18 : #define _WIN32_WINNT 0x0501 19 : #ifndef WIN32_LEAN_AND_MEAN 20 : #define WIN32_LEAN_AND_MEAN 1 21 : #endif 22 : #ifndef NOMINMAX 23 : #define NOMINMAX 24 : #endif 25 : #ifdef FD_SETSIZE 26 : #undef FD_SETSIZE // prevent redefinition compiler warning 27 : #endif 28 : #define FD_SETSIZE 1024 // max number of fds in fd_set 29 : 30 : #include <winsock2.h> // Must be included before mswsock.h and windows.h 31 : 32 : #include <mswsock.h> 33 : #include <windows.h> 34 : #include <ws2tcpip.h> 35 : #else 36 : #include <arpa/inet.h> 37 : #include <ifaddrs.h> 38 : #include <limits.h> 39 : #include <net/if.h> 40 : #include <netdb.h> 41 : #include <netinet/in.h> 42 : #include <sys/fcntl.h> 43 : #include <sys/mman.h> 44 : #include <sys/socket.h> 45 : #include <sys/types.h> 46 : #include <unistd.h> 47 : #endif 48 : 49 : #ifdef WIN32 50 : #define MSG_DONTWAIT 0 51 : #else 52 : typedef u_int SOCKET; 53 : #include "errno.h" 54 : #define WSAGetLastError() errno 55 : #define WSAEINVAL EINVAL 56 : #define WSAEALREADY EALREADY 57 : #define WSAEWOULDBLOCK EWOULDBLOCK 58 : #define WSAEMSGSIZE EMSGSIZE 59 : #define WSAEINTR EINTR 60 : #define WSAEINPROGRESS EINPROGRESS 61 : #define WSAEADDRINUSE EADDRINUSE 62 : #define WSAENOTSOCK EBADF 63 : #define INVALID_SOCKET (SOCKET)(~0) 64 : #define SOCKET_ERROR -1 65 : #endif 66 : 67 : #ifdef WIN32 68 : #ifndef S_IRUSR 69 : #define S_IRUSR 0400 70 : #define S_IWUSR 0200 71 : #endif 72 : #else 73 : #define MAX_PATH 1024 74 : #endif 75 : 76 : // As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0 77 : #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) 78 : #define MSG_NOSIGNAL 0 79 : #endif 80 : 81 : #ifndef WIN32 82 : // PRIO_MAX is not defined on Solaris 83 : #ifndef PRIO_MAX 84 : #define PRIO_MAX 20 85 : #endif 86 : #define THREAD_PRIORITY_LOWEST PRIO_MAX 87 : #define THREAD_PRIORITY_BELOW_NORMAL 2 88 : #define THREAD_PRIORITY_NORMAL 0 89 : #define THREAD_PRIORITY_ABOVE_NORMAL (-2) 90 : #endif 91 : 92 : #if HAVE_DECL_STRNLEN == 0 93 : size_t strnlen( const char *start, size_t max_len); 94 : #endif // HAVE_DECL_STRNLEN 95 : 96 : #ifndef WIN32 97 : typedef void* sockopt_arg_type; 98 : #else 99 : typedef char* sockopt_arg_type; 100 : #endif 101 : 102 : // Note these both should work with the current usage of poll, but best to be safe 103 : // WIN32 poll is broken https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/ 104 : // __APPLE__ poll is broke https://github.com/bitcoin/bitcoin/pull/14336#issuecomment-437384408 105 : #if defined(__linux__) 106 : #define USE_POLL 107 : #endif 108 : 109 4391 : bool static inline IsSelectableSocket(const SOCKET& s) { 110 : #if defined(USE_POLL) || defined(WIN32) 111 4391 : return true; 112 : #else 113 : return (s < FD_SETSIZE); 114 : #endif 115 : } 116 : 117 : #endif // PIVX_COMPAT_H