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 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2013 The Bitcoin developers
  3. // Distributed under the MIT/X11 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. #ifdef WIN32
  8. #ifdef _WIN32_WINNT
  9. #undef _WIN32_WINNT
  10. #endif
  11. #define _WIN32_WINNT 0x0501
  12. #define WIN32_LEAN_AND_MEAN 1
  13. #ifndef NOMINMAX
  14. #define NOMINMAX
  15. #endif
  16. #ifdef FD_SETSIZE
  17. #undef FD_SETSIZE // prevent redefinition compiler warning
  18. #endif
  19. #define FD_SETSIZE 1024 // max number of fds in fd_set
  20. #include <winsock2.h> // Must be included before mswsock.h and windows.h
  21. #include <mswsock.h>
  22. #include <windows.h>
  23. #include <ws2tcpip.h>
  24. #else
  25. #include <arpa/inet.h>
  26. #include <ifaddrs.h>
  27. #include <limits.h>
  28. #include <net/if.h>
  29. #include <netdb.h>
  30. #include <netinet/in.h>
  31. #include <sys/fcntl.h>
  32. #include <sys/mman.h>
  33. #include <sys/socket.h>
  34. #include <sys/types.h>
  35. #include <unistd.h>
  36. #endif
  37. #ifdef WIN32
  38. #define MSG_DONTWAIT 0
  39. #else
  40. typedef u_int SOCKET;
  41. #include "errno.h"
  42. #define WSAGetLastError() errno
  43. #define WSAEINVAL EINVAL
  44. #define WSAEALREADY EALREADY
  45. #define WSAEWOULDBLOCK EWOULDBLOCK
  46. #define WSAEMSGSIZE EMSGSIZE
  47. #define WSAEINTR EINTR
  48. #define WSAEINPROGRESS EINPROGRESS
  49. #define WSAEADDRINUSE EADDRINUSE
  50. #define WSAENOTSOCK EBADF
  51. #define INVALID_SOCKET (SOCKET)(~0)
  52. #define SOCKET_ERROR -1
  53. #endif
  54. inline int myclosesocket(SOCKET& hSocket)
  55. {
  56. if (hSocket == INVALID_SOCKET)
  57. return WSAENOTSOCK;
  58. #ifdef WIN32
  59. int ret = closesocket(hSocket);
  60. #else
  61. int ret = close(hSocket);
  62. #endif
  63. hSocket = INVALID_SOCKET;
  64. return ret;
  65. }
  66. #define closesocket(s) myclosesocket(s)
  67. #endif