compat.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
  2. #ifndef _ECOIN_COMPAT_H
  3. #define _ECOIN_COMPAT_H 1
  4. #ifdef WIN32
  5. #define _WIN32_WINNT 0x0501
  6. #define WIN32_LEAN_AND_MEAN 1
  7. #ifndef NOMINMAX
  8. #define NOMINMAX
  9. #endif
  10. #include <winsock2.h>
  11. #include <mswsock.h>
  12. #include <ws2tcpip.h>
  13. #else
  14. #include <sys/types.h>
  15. #include <sys/socket.h>
  16. #include <sys/fcntl.h>
  17. #include <arpa/inet.h>
  18. #include <netdb.h>
  19. #include <net/if.h>
  20. #include <netinet/in.h>
  21. #include <ifaddrs.h>
  22. typedef u_int SOCKET;
  23. #endif
  24. #ifdef WIN32
  25. #define MSG_NOSIGNAL 0
  26. #define MSG_DONTWAIT 0
  27. typedef int socklen_t;
  28. #else
  29. #include "errno.h"
  30. #define WSAGetLastError() errno
  31. #define WSAEINVAL EINVAL
  32. #define WSAEALREADY EALREADY
  33. #define WSAEWOULDBLOCK EWOULDBLOCK
  34. #define WSAEMSGSIZE EMSGSIZE
  35. #define WSAEINTR EINTR
  36. #define WSAEINPROGRESS EINPROGRESS
  37. #define WSAEADDRINUSE EADDRINUSE
  38. #define WSAENOTSOCK EBADF
  39. #define INVALID_SOCKET (SOCKET)(~0)
  40. #define SOCKET_ERROR -1
  41. #endif
  42. inline int myclosesocket(SOCKET& hSocket)
  43. {
  44. if (hSocket == INVALID_SOCKET)
  45. return WSAENOTSOCK;
  46. #ifdef WIN32
  47. int ret = closesocket(hSocket);
  48. #else
  49. int ret = close(hSocket);
  50. #endif
  51. hSocket = INVALID_SOCKET;
  52. return ret;
  53. }
  54. #define closesocket(s) myclosesocket(s)
  55. #endif