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