]>
Commit | Line | Data |
---|---|---|
67a42f92 | 1 | // Copyright (c) 2009-2010 Satoshi Nakamoto |
f914f1a7 | 2 | // Copyright (c) 2009-2014 The Bitcoin Core developers |
78253fcb | 3 | // Distributed under the MIT software license, see the accompanying |
bc909a7a | 4 | // file COPYING or https://www.opensource.org/licenses/mit-license.php . |
51ed9ec9 | 5 | |
84738627 PJ |
6 | #ifndef BITCOIN_COMPAT_H |
7 | #define BITCOIN_COMPAT_H | |
67a42f92 | 8 | |
c8ed6130 PJ |
9 | #if defined(HAVE_CONFIG_H) |
10 | #include "config/bitcoin-config.h" | |
11 | #endif | |
12 | ||
9cb1ec9c | 13 | #ifdef _WIN32 |
733511ed PK |
14 | #ifdef _WIN32_WINNT |
15 | #undef _WIN32_WINNT | |
16 | #endif | |
ed6d0b5f | 17 | #define _WIN32_WINNT 0x0501 |
00788416 | 18 | #ifndef WIN32_LEAN_AND_MEAN |
ed6d0b5f | 19 | #define WIN32_LEAN_AND_MEAN 1 |
00788416 | 20 | #endif |
ed6d0b5f PW |
21 | #ifndef NOMINMAX |
22 | #define NOMINMAX | |
23 | #endif | |
733511ed PK |
24 | #ifdef FD_SETSIZE |
25 | #undef FD_SETSIZE // prevent redefinition compiler warning | |
26 | #endif | |
33912d1f | 27 | #define FD_SETSIZE 1024 // max number of fds in fd_set |
51ed9ec9 BD |
28 | |
29 | #include <winsock2.h> // Must be included before mswsock.h and windows.h | |
30 | ||
31 | #include <mswsock.h> | |
32 | #include <windows.h> | |
ed6d0b5f PW |
33 | #include <ws2tcpip.h> |
34 | #else | |
0ee86d39 | 35 | #include <fcntl.h> |
2364b118 FR |
36 | #include <sys/mman.h> |
37 | #include <sys/socket.h> | |
9ac5a01c | 38 | #include <sys/types.h> |
2364b118 FR |
39 | #include <net/if.h> |
40 | #include <netinet/in.h> | |
95a50390 | 41 | #include <netinet/tcp.h> |
ed6d0b5f | 42 | #include <arpa/inet.h> |
51ed9ec9 BD |
43 | #include <ifaddrs.h> |
44 | #include <limits.h> | |
51ed9ec9 | 45 | #include <netdb.h> |
51ed9ec9 | 46 | #include <unistd.h> |
ed6d0b5f PW |
47 | #endif |
48 | ||
9cb1ec9c | 49 | #ifdef _WIN32 |
67a42f92 | 50 | #define MSG_DONTWAIT 0 |
67a42f92 | 51 | #else |
dd833a4c | 52 | typedef u_int SOCKET; |
67a42f92 PW |
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 | ||
9cb1ec9c | 67 | #ifdef _WIN32 |
b4aa769b WL |
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 | ||
9cb1ec9c | 81 | #ifndef _WIN32 |
610a8c07 WL |
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 | ||
494f6e7d PJ |
92 | #if HAVE_DECL_STRNLEN == 0 |
93 | size_t strnlen( const char *start, size_t max_len); | |
94 | #endif // HAVE_DECL_STRNLEN | |
95 | ||
0095b9a1 | 96 | bool static inline IsSelectableSocket(SOCKET s) { |
9cb1ec9c | 97 | #ifdef _WIN32 |
0095b9a1 PW |
98 | return true; |
99 | #else | |
e8b87c8f | 100 | return (s < FD_SETSIZE); |
0095b9a1 PW |
101 | #endif |
102 | } | |
103 | ||
84738627 | 104 | #endif // BITCOIN_COMPAT_H |