]>
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 |
3a25a2b9 | 4 | // file COPYING or http://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 | ||
ed6d0b5f | 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 | |
2364b118 FR |
35 | #include <sys/fcntl.h> |
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> | |
ed6d0b5f | 41 | #include <arpa/inet.h> |
51ed9ec9 BD |
42 | #include <ifaddrs.h> |
43 | #include <limits.h> | |
51ed9ec9 | 44 | #include <netdb.h> |
51ed9ec9 | 45 | #include <unistd.h> |
ed6d0b5f PW |
46 | #endif |
47 | ||
67a42f92 | 48 | #ifdef WIN32 |
67a42f92 | 49 | #define MSG_DONTWAIT 0 |
67a42f92 | 50 | #else |
dd833a4c | 51 | typedef u_int SOCKET; |
67a42f92 PW |
52 | #include "errno.h" |
53 | #define WSAGetLastError() errno | |
54 | #define WSAEINVAL EINVAL | |
55 | #define WSAEALREADY EALREADY | |
56 | #define WSAEWOULDBLOCK EWOULDBLOCK | |
57 | #define WSAEMSGSIZE EMSGSIZE | |
58 | #define WSAEINTR EINTR | |
59 | #define WSAEINPROGRESS EINPROGRESS | |
60 | #define WSAEADDRINUSE EADDRINUSE | |
61 | #define WSAENOTSOCK EBADF | |
62 | #define INVALID_SOCKET (SOCKET)(~0) | |
63 | #define SOCKET_ERROR -1 | |
64 | #endif | |
65 | ||
b4aa769b WL |
66 | #ifdef WIN32 |
67 | #ifndef S_IRUSR | |
68 | #define S_IRUSR 0400 | |
69 | #define S_IWUSR 0200 | |
70 | #endif | |
71 | #else | |
72 | #define MAX_PATH 1024 | |
73 | #endif | |
74 | ||
75 | // As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0 | |
76 | #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) | |
77 | #define MSG_NOSIGNAL 0 | |
78 | #endif | |
79 | ||
610a8c07 WL |
80 | #ifndef WIN32 |
81 | // PRIO_MAX is not defined on Solaris | |
82 | #ifndef PRIO_MAX | |
83 | #define PRIO_MAX 20 | |
84 | #endif | |
85 | #define THREAD_PRIORITY_LOWEST PRIO_MAX | |
86 | #define THREAD_PRIORITY_BELOW_NORMAL 2 | |
87 | #define THREAD_PRIORITY_NORMAL 0 | |
88 | #define THREAD_PRIORITY_ABOVE_NORMAL (-2) | |
89 | #endif | |
90 | ||
494f6e7d PJ |
91 | #if HAVE_DECL_STRNLEN == 0 |
92 | size_t strnlen( const char *start, size_t max_len); | |
93 | #endif // HAVE_DECL_STRNLEN | |
94 | ||
0095b9a1 PW |
95 | bool static inline IsSelectableSocket(SOCKET s) { |
96 | #ifdef WIN32 | |
97 | return true; | |
98 | #else | |
99 | return (s >= 0 && s < FD_SETSIZE); | |
100 | #endif | |
101 | } | |
102 | ||
84738627 | 103 | #endif // BITCOIN_COMPAT_H |