Dogecoin Core  1.14.2
P2P Digital Currency
compat.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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 #ifdef _WIN32_WINNT
15 #undef _WIN32_WINNT
16 #endif
17 #define _WIN32_WINNT 0x0501
18 #ifndef WIN32_LEAN_AND_MEAN
19 #define WIN32_LEAN_AND_MEAN 1
20 #endif
21 #ifndef NOMINMAX
22 #define NOMINMAX
23 #endif
24 #ifdef FD_SETSIZE
25 #undef FD_SETSIZE // prevent redefinition compiler warning
26 #endif
27 #define FD_SETSIZE 1024 // max number of fds in fd_set
28 
29 #include <winsock2.h> // Must be included before mswsock.h and windows.h
30 
31 #include <mswsock.h>
32 #include <windows.h>
33 #include <ws2tcpip.h>
34 #else
35 #include <sys/fcntl.h>
36 #include <sys/mman.h>
37 #include <sys/select.h>
38 #include <sys/socket.h>
39 #include <sys/types.h>
40 #include <net/if.h>
41 #include <netinet/in.h>
42 #include <netinet/tcp.h>
43 #include <arpa/inet.h>
44 #include <ifaddrs.h>
45 #include <limits.h>
46 #include <netdb.h>
47 #include <unistd.h>
48 #endif
49 
50 #ifdef WIN32
51 #define MSG_DONTWAIT 0
52 #else
53 typedef u_int SOCKET;
54 #include "errno.h"
55 #define WSAGetLastError() errno
56 #define WSAEINVAL EINVAL
57 #define WSAEALREADY EALREADY
58 #define WSAEWOULDBLOCK EWOULDBLOCK
59 #define WSAEMSGSIZE EMSGSIZE
60 #define WSAEINTR EINTR
61 #define WSAEINPROGRESS EINPROGRESS
62 #define WSAEADDRINUSE EADDRINUSE
63 #define WSAENOTSOCK EBADF
64 #define INVALID_SOCKET (SOCKET)(~0)
65 #define SOCKET_ERROR -1
66 #endif
67 
68 #ifdef WIN32
69 #ifndef S_IRUSR
70 #define S_IRUSR 0400
71 #define S_IWUSR 0200
72 #endif
73 #else
74 #define MAX_PATH 1024
75 #endif
76 
77 // As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0
78 #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
79 #define MSG_NOSIGNAL 0
80 #endif
81 
82 #if HAVE_DECL_STRNLEN == 0
83 size_t strnlen( const char *start, size_t max_len);
84 #endif // HAVE_DECL_STRNLEN
85 
86 bool static inline IsSelectableSocket(SOCKET s) {
87 #ifdef WIN32
88  return true;
89 #else
90  return (s < FD_SETSIZE);
91 #endif
92 }
93 
94 #endif // BITCOIN_COMPAT_H
u_int SOCKET
Definition: compat.h:53
size_t strnlen(const char *start, size_t max_len)
Definition: strnlen.cpp:12