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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2016 The Starwels 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 STARWELS_COMPAT_H
  6. #define STARWELS_COMPAT_H
  7. #if defined(HAVE_CONFIG_H)
  8. #include "config/starwels-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/select.h>
  33. #include <sys/socket.h>
  34. #include <sys/types.h>
  35. #include <net/if.h>
  36. #include <netinet/in.h>
  37. #include <netinet/tcp.h>
  38. #include <arpa/inet.h>
  39. #include <ifaddrs.h>
  40. #include <limits.h>
  41. #include <netdb.h>
  42. #include <unistd.h>
  43. #endif
  44. #ifndef WIN32
  45. typedef unsigned int SOCKET;
  46. #include "errno.h"
  47. #define WSAGetLastError() errno
  48. #define WSAEINVAL EINVAL
  49. #define WSAEALREADY EALREADY
  50. #define WSAEWOULDBLOCK EWOULDBLOCK
  51. #define WSAEMSGSIZE EMSGSIZE
  52. #define WSAEINTR EINTR
  53. #define WSAEINPROGRESS EINPROGRESS
  54. #define WSAEADDRINUSE EADDRINUSE
  55. #define WSAENOTSOCK EBADF
  56. #define INVALID_SOCKET (SOCKET)(~0)
  57. #define SOCKET_ERROR -1
  58. #endif
  59. #ifdef WIN32
  60. #ifndef S_IRUSR
  61. #define S_IRUSR 0400
  62. #define S_IWUSR 0200
  63. #endif
  64. #else
  65. #define MAX_PATH 1024
  66. #endif
  67. #if HAVE_DECL_STRNLEN == 0
  68. size_t strnlen( const char *start, size_t max_len);
  69. #endif // HAVE_DECL_STRNLEN
  70. bool static inline IsSelectableSocket(const SOCKET& s) {
  71. #ifdef WIN32
  72. return true;
  73. #else
  74. return (s < FD_SETSIZE);
  75. #endif
  76. }
  77. #endif // STARWELS_COMPAT_H