Bitcoin Core
26.1.0
P2P Digital Currency
src
compat
compat.h
Go to the documentation of this file.
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-2022 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_COMPAT_H
7
#define BITCOIN_COMPAT_COMPAT_H
8
9
#if defined(HAVE_CONFIG_H)
10
#include <
config/bitcoin-config.h
>
11
#endif
12
13
// Windows defines FD_SETSIZE to 64 (see _fd_types.h in mingw-w64),
14
// which is too small for our usage, but allows us to redefine it safely.
15
// We redefine it to be 1024, to match glibc, see typesizes.h.
16
#ifdef WIN32
17
#ifdef FD_SETSIZE
18
#undef FD_SETSIZE
19
#endif
20
#define FD_SETSIZE 1024
21
#include <winsock2.h>
22
#include <ws2tcpip.h>
23
#include <cstdint>
24
#else
25
#include <arpa/inet.h>
// IWYU pragma: export
26
#include <fcntl.h>
// IWYU pragma: export
27
#include <ifaddrs.h>
// IWYU pragma: export
28
#include <net/if.h>
// IWYU pragma: export
29
#include <netdb.h>
// IWYU pragma: export
30
#include <netinet/in.h>
// IWYU pragma: export
31
#include <netinet/tcp.h>
// IWYU pragma: export
32
#include <sys/mman.h>
// IWYU pragma: export
33
#include <sys/select.h>
// IWYU pragma: export
34
#include <sys/socket.h>
// IWYU pragma: export
35
#include <sys/types.h>
// IWYU pragma: export
36
#include <unistd.h>
// IWYU pragma: export
37
#endif
38
39
// We map Linux / BSD error functions and codes, to the equivalent
40
// Windows definitions, and use the WSA* names throughout our code.
41
// Note that glibc defines EWOULDBLOCK as EAGAIN (see errno.h).
42
#ifndef WIN32
43
typedef
unsigned
int
SOCKET
;
44
#include <cerrno>
45
#define WSAGetLastError() errno
46
#define WSAEINVAL EINVAL
47
#define WSAEWOULDBLOCK EWOULDBLOCK
48
#define WSAEAGAIN EAGAIN
49
#define WSAEMSGSIZE EMSGSIZE
50
#define WSAEINTR EINTR
51
#define WSAEINPROGRESS EINPROGRESS
52
#define WSAEADDRINUSE EADDRINUSE
53
#define INVALID_SOCKET (SOCKET)(~0)
54
#define SOCKET_ERROR -1
55
#else
56
// WSAEAGAIN doesn't exist on Windows
57
#ifdef EAGAIN
58
#define WSAEAGAIN EAGAIN
59
#else
60
#define WSAEAGAIN WSAEWOULDBLOCK
61
#endif
62
#endif
63
64
// Windows defines MAX_PATH as it's maximum path length.
65
// We define MAX_PATH for use on non-Windows systems.
66
#ifndef WIN32
67
#define MAX_PATH 1024
68
#endif
69
70
// ssize_t is POSIX, and not present when using MSVC.
71
#ifdef _MSC_VER
72
#include <BaseTsd.h>
73
typedef
SSIZE_T ssize_t;
74
#endif
75
76
// The type of the option value passed to getsockopt & setsockopt
77
// differs between Windows and non-Windows.
78
#ifndef WIN32
79
typedef
void
*
sockopt_arg_type
;
80
#else
81
typedef
char
*
sockopt_arg_type
;
82
#endif
83
84
#ifdef WIN32
85
// Export main() and ensure working ASLR when using mingw-w64.
86
// Exporting a symbol will prevent the linker from stripping
87
// the .reloc section from the binary, which is a requirement
88
// for ASLR. While release builds are not affected, anyone
89
// building with a binutils < 2.36 is subject to this ld bug.
90
#define MAIN_FUNCTION __declspec(dllexport) int main(int argc, char* argv[])
91
#else
92
#define MAIN_FUNCTION int main(int argc, char* argv[])
93
#endif
94
95
// Note these both should work with the current usage of poll, but best to be safe
96
// WIN32 poll is broken https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/
97
// __APPLE__ poll is broke https://github.com/bitcoin/bitcoin/pull/14336#issuecomment-437384408
98
#if defined(__linux__)
99
#define USE_POLL
100
#endif
101
102
// MSG_NOSIGNAL is not available on some platforms, if it doesn't exist define it as 0
103
#if !defined(MSG_NOSIGNAL)
104
#define MSG_NOSIGNAL 0
105
#endif
106
107
// MSG_DONTWAIT is not available on some platforms, if it doesn't exist define it as 0
108
#if !defined(MSG_DONTWAIT)
109
#define MSG_DONTWAIT 0
110
#endif
111
112
#endif // BITCOIN_COMPAT_COMPAT_H
sockopt_arg_type
void * sockopt_arg_type
Definition:
compat.h:79
bitcoin-config.h
SOCKET
unsigned int SOCKET
Definition:
compat.h:43
Generated on Thu Mar 28 2024 12:00:00 for Bitcoin Core by
1.8.14