Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

compat.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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/dash-config.h>
11 #endif
12 
13 #include <type_traits>
14 
15 // GCC 4.8 is missing some C++11 type_traits,
16 // https://www.gnu.org/software/gcc/gcc-5/changes.html
17 #if defined(__GNUC__) && __GNUC__ < 5
18 #define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivial
19 #else
20 #define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivially_constructible
21 #endif
22 
23 #ifdef WIN32
24 #ifdef _WIN32_WINNT
25 #undef _WIN32_WINNT
26 #endif
27 #define _WIN32_WINNT 0x0501
28 #ifndef WIN32_LEAN_AND_MEAN
29 #define WIN32_LEAN_AND_MEAN 1
30 #endif
31 #ifndef NOMINMAX
32 #define NOMINMAX
33 #endif
34 #ifdef FD_SETSIZE
35 #undef FD_SETSIZE // prevent redefinition compiler warning
36 #endif
37 #define FD_SETSIZE 1024 // max number of fds in fd_set
38 
39 #include <winsock2.h> // Must be included before mswsock.h and windows.h
40 
41 #include <mswsock.h>
42 #include <windows.h>
43 #include <ws2tcpip.h>
44 #include <stdint.h>
45 #else
46 #include <fcntl.h>
47 #include <sys/mman.h>
48 #include <sys/select.h>
49 #include <sys/socket.h>
50 #include <sys/types.h>
51 #include <net/if.h>
52 #include <netinet/in.h>
53 #include <netinet/tcp.h>
54 #include <arpa/inet.h>
55 #include <ifaddrs.h>
56 #include <limits.h>
57 #include <netdb.h>
58 #include <unistd.h>
59 #endif
60 
61 #ifndef WIN32
62 typedef unsigned int SOCKET;
63 #include <errno.h>
64 #define WSAGetLastError() errno
65 #define WSAEINVAL EINVAL
66 #define WSAEALREADY EALREADY
67 #define WSAEWOULDBLOCK EWOULDBLOCK
68 #define WSAEMSGSIZE EMSGSIZE
69 #define WSAEINTR EINTR
70 #define WSAEINPROGRESS EINPROGRESS
71 #define WSAEADDRINUSE EADDRINUSE
72 #define WSAENOTSOCK EBADF
73 #define INVALID_SOCKET (SOCKET)(~0)
74 #define SOCKET_ERROR -1
75 #define SD_SEND SHUT_WR
76 #endif
77 
78 #ifdef WIN32
79 #ifndef S_IRUSR
80 #define S_IRUSR 0400
81 #define S_IWUSR 0200
82 #endif
83 #else
84 #define MAX_PATH 1024
85 #endif
86 #ifdef _MSC_VER
87 #if !defined(ssize_t)
88 #ifdef _WIN64
89 typedef int64_t ssize_t;
90 #else
91 typedef int32_t ssize_t;
92 #endif
93 #endif
94 #endif
95 
96 #if HAVE_DECL_STRNLEN == 0
97 size_t strnlen( const char *start, size_t max_len);
98 #endif // HAVE_DECL_STRNLEN
99 
100 #ifndef WIN32
101 typedef void* sockopt_arg_type;
102 #else
103 typedef char* sockopt_arg_type;
104 #endif
105 
106 // Note these both should work with the current usage of poll, but best to be safe
107 // WIN32 poll is broken https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/
108 // __APPLE__ poll is broke https://github.com/bitcoin/bitcoin/pull/14336#issuecomment-437384408
109 #if defined(__linux__)
110 #define USE_POLL
111 #endif
112 
113 #if defined(__linux__)
114 #define USE_EPOLL
115 #endif
116 
117 bool static inline IsSelectableSocket(const SOCKET& s) {
118 #if defined(USE_POLL) || defined(WIN32)
119  return true;
120 #else
121  return (s < FD_SETSIZE);
122 #endif
123 }
124 
125 #endif // BITCOIN_COMPAT_H
static bool IsSelectableSocket(const SOCKET &s)
Definition: compat.h:117
void * sockopt_arg_type
Definition: compat.h:101
unsigned int SOCKET
Definition: compat.h:62
size_t strnlen(const char *start, size_t max_len)
Definition: strnlen.cpp:12
Released under the MIT license