PIVX Core  5.6.99
P2P Digital Currency
compat.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2017-2021 The PIVX Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef PIVX_COMPAT_H
8 #define PIVX_COMPAT_H
9 
10 #if defined(HAVE_CONFIG_H)
11 #include "config/pivx-config.h"
12 #endif
13 
14 #ifdef WIN32
15 #ifdef _WIN32_WINNT
16 #undef _WIN32_WINNT
17 #endif
18 #define _WIN32_WINNT 0x0501
19 #ifndef WIN32_LEAN_AND_MEAN
20 #define WIN32_LEAN_AND_MEAN 1
21 #endif
22 #ifndef NOMINMAX
23 #define NOMINMAX
24 #endif
25 #ifdef FD_SETSIZE
26 #undef FD_SETSIZE // prevent redefinition compiler warning
27 #endif
28 #define FD_SETSIZE 1024 // max number of fds in fd_set
29 
30 #include <winsock2.h> // Must be included before mswsock.h and windows.h
31 
32 #include <mswsock.h>
33 #include <windows.h>
34 #include <ws2tcpip.h>
35 #else
36 #include <arpa/inet.h>
37 #include <ifaddrs.h>
38 #include <limits.h>
39 #include <net/if.h>
40 #include <netdb.h>
41 #include <netinet/in.h>
42 #include <netinet/tcp.h>
43 #include <sys/fcntl.h>
44 #include <sys/mman.h>
45 #include <sys/socket.h>
46 #include <sys/types.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 #ifndef WIN32
83 // PRIO_MAX is not defined on Solaris
84 #ifndef PRIO_MAX
85 #define PRIO_MAX 20
86 #endif
87 #define THREAD_PRIORITY_LOWEST PRIO_MAX
88 #define THREAD_PRIORITY_BELOW_NORMAL 2
89 #define THREAD_PRIORITY_NORMAL 0
90 #define THREAD_PRIORITY_ABOVE_NORMAL (-2)
91 #endif
92 
93 #if HAVE_DECL_STRNLEN == 0
94 size_t strnlen( const char *start, size_t max_len);
95 #endif // HAVE_DECL_STRNLEN
96 
97 #ifndef WIN32
98 typedef void* sockopt_arg_type;
99 #else
100 typedef char* sockopt_arg_type;
101 #endif
102 
103 // Note these both should work with the current usage of poll, but best to be safe
104 // WIN32 poll is broken https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/
105 // __APPLE__ poll is broke https://github.com/bitcoin/bitcoin/pull/14336#issuecomment-437384408
106 #if defined(__linux__)
107 #define USE_POLL
108 #endif
109 
110 bool static inline IsSelectableSocket(const SOCKET& s) {
111 #if defined(USE_POLL) || defined(WIN32)
112  return true;
113 #else
114  return (s < FD_SETSIZE);
115 #endif
116 }
117 
118 #endif // PIVX_COMPAT_H
u_int SOCKET
Definition: compat.h:53
size_t strnlen(const char *start, size_t max_len)
Definition: strnlen.cpp:12
void * sockopt_arg_type
Definition: compat.h:98