You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compat.h 2.4KB

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