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