windows.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
  3. This file is part of libzmq, the ZeroMQ core engine in C++.
  4. libzmq is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU Lesser General Public License (LGPL) as published
  6. by the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. As a special exception, the Contributors give you permission to link
  9. this library with independent modules to produce an executable,
  10. regardless of the license terms of these independent modules, and to
  11. copy and distribute the resulting executable under terms of your choice,
  12. provided that you also meet, for each linked independent module, the
  13. terms and conditions of the license of that module. An independent
  14. module is a module which is not derived from or based on this library.
  15. If you modify this library, you must extend this exception to your
  16. version of the library.
  17. libzmq is distributed in the hope that it will be useful, but WITHOUT
  18. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  20. License for more details.
  21. You should have received a copy of the GNU Lesser General Public License
  22. along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #ifndef __ZMQ_WINDOWS_HPP_INCLUDED__
  25. #define __ZMQ_WINDOWS_HPP_INCLUDED__
  26. #ifndef _CRT_SECURE_NO_WARNINGS
  27. #define _CRT_SECURE_NO_WARNINGS
  28. #endif
  29. #ifndef NOMINMAX
  30. #define NOMINMAX // Macros min(a,b) and max(a,b)
  31. #endif
  32. // Set target version to Windows Server 2008, Windows Vista or higher.
  33. // Windows XP (0x0501) is supported but without client & server socket types.
  34. #if !defined _WIN32_WINNT && !defined ZMQ_HAVE_WINDOWS_UWP
  35. #define _WIN32_WINNT 0x0600
  36. #endif
  37. #ifdef __MINGW32__
  38. // Require Windows XP or higher with MinGW for getaddrinfo().
  39. #if (_WIN32_WINNT >= 0x0501)
  40. #else
  41. #error You need at least Windows XP target
  42. #endif
  43. #endif
  44. #include <winsock2.h>
  45. #include <windows.h>
  46. #include <mswsock.h>
  47. #include <iphlpapi.h>
  48. #if !defined __MINGW32__
  49. #include <mstcpip.h>
  50. #endif
  51. // Workaround missing mstcpip.h in mingw32 (MinGW64 provides this)
  52. // __MINGW64_VERSION_MAJOR is only defined when using in mingw-w64
  53. #if defined __MINGW32__ && !defined SIO_KEEPALIVE_VALS \
  54. && !defined __MINGW64_VERSION_MAJOR
  55. struct tcp_keepalive
  56. {
  57. u_long onoff;
  58. u_long keepalivetime;
  59. u_long keepaliveinterval;
  60. };
  61. #define SIO_KEEPALIVE_VALS _WSAIOW (IOC_VENDOR, 4)
  62. #endif
  63. #include <ws2tcpip.h>
  64. #include <ipexport.h>
  65. #if !defined _WIN32_WCE
  66. #include <process.h>
  67. #endif
  68. #if defined ZMQ_IOTHREAD_POLLER_USE_POLL || defined ZMQ_POLL_BASED_ON_POLL
  69. static inline int poll (struct pollfd *pfd, unsigned long nfds, int timeout)
  70. {
  71. return WSAPoll (pfd, nfds, timeout);
  72. }
  73. #endif
  74. // In MinGW environment AI_NUMERICSERV is not defined.
  75. #ifndef AI_NUMERICSERV
  76. #define AI_NUMERICSERV 0x0400
  77. #endif
  78. #endif
  79. // In MSVC prior to v14, snprintf is not available
  80. // The closest implementation is the _snprintf_s function
  81. #if defined(_MSC_VER) && _MSC_VER < 1900
  82. #define snprintf(buffer_, count_, format_, ...) \
  83. _snprintf_s (buffer_, count_, _TRUNCATE, format_, __VA_ARGS__)
  84. #endif