private-lib-plat-windows.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * libwebsockets - small server side websockets and web server implementation
  3. *
  4. * Copyright (C) 2010 - 2019 Andy Green <[email protected]>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to
  8. * deal in the Software without restriction, including without limitation the
  9. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22. * IN THE SOFTWARE.
  23. *
  24. * Included from lib/private-lib-core.h if defined(WIN32) || defined(_WIN32)
  25. */
  26. #ifndef WIN32_LEAN_AND_MEAN
  27. #define WIN32_LEAN_AND_MEAN
  28. #endif
  29. #if defined(WINVER) && (WINVER < 0x0501)
  30. #undef WINVER
  31. #undef _WIN32_WINNT
  32. #define WINVER 0x0501
  33. #define _WIN32_WINNT WINVER
  34. #endif
  35. #define LWS_NO_DAEMONIZE
  36. #define LWS_ERRNO WSAGetLastError()
  37. #define LWS_EAGAIN WSAEWOULDBLOCK
  38. #define LWS_EALREADY WSAEALREADY
  39. #define LWS_EINPROGRESS WSAEINPROGRESS
  40. #define LWS_EINTR WSAEINTR
  41. #define LWS_EISCONN WSAEISCONN
  42. #define LWS_ENOTCONN WSAENOTCONN
  43. #define LWS_EWOULDBLOCK WSAEWOULDBLOCK
  44. #define LWS_EADDRINUSE WSAEADDRINUSE
  45. #define MSG_NOSIGNAL 0
  46. #define SHUT_RDWR SD_BOTH
  47. #define SOL_TCP IPPROTO_TCP
  48. #define SHUT_WR SD_SEND
  49. #define compatible_close(fd) closesocket(fd)
  50. #define compatible_file_close(fd) CloseHandle(fd)
  51. #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1
  52. #include <winsock2.h>
  53. #include <ws2tcpip.h>
  54. #include <windows.h>
  55. #include <tchar.h>
  56. #ifdef LWS_HAVE_IN6ADDR_H
  57. #include <in6addr.h>
  58. #endif
  59. #include <mstcpip.h>
  60. #include <io.h>
  61. #if defined(LWS_WITH_UNIX_SOCK)
  62. #include <afunix.h>
  63. #endif
  64. #if defined(LWS_HAVE_PTHREAD_H)
  65. #define lws_mutex_t pthread_mutex_t
  66. #define lws_mutex_init(x) pthread_mutex_init(&(x), NULL)
  67. #define lws_mutex_destroy(x) pthread_mutex_destroy(&(x))
  68. #define lws_mutex_lock(x) pthread_mutex_lock(&(x))
  69. #define lws_mutex_unlock(x) pthread_mutex_unlock(&(x))
  70. #endif
  71. #if !defined(LWS_HAVE_ATOLL)
  72. #if defined(LWS_HAVE__ATOI64)
  73. #define atoll _atoi64
  74. #else
  75. #warning No atoll or _atoi64 available, using atoi
  76. #define atoll atoi
  77. #endif
  78. #endif
  79. #ifndef __func__
  80. #define __func__ __FUNCTION__
  81. #endif
  82. #ifdef LWS_HAVE__VSNPRINTF
  83. #define vsnprintf _vsnprintf
  84. #endif
  85. /* we don't have an implementation for this on windows... */
  86. int kill(int pid, int sig);
  87. int fork(void);
  88. #ifndef SIGINT
  89. #define SIGINT 2
  90. #endif
  91. #include <gettimeofday.h>
  92. #ifndef BIG_ENDIAN
  93. #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */
  94. #endif
  95. #ifndef LITTLE_ENDIAN
  96. #define LITTLE_ENDIAN 1234
  97. #endif
  98. #ifndef BYTE_ORDER
  99. #define BYTE_ORDER LITTLE_ENDIAN
  100. #endif
  101. #undef __P
  102. #ifndef __P
  103. #if __STDC__
  104. #define __P(protos) protos
  105. #else
  106. #define __P(protos) ()
  107. #endif
  108. #endif
  109. #ifdef _WIN32
  110. #ifndef FD_HASHTABLE_MODULUS
  111. #define FD_HASHTABLE_MODULUS 32
  112. #endif
  113. #endif
  114. #define lws_plat_socket_offset() (0)
  115. struct lws;
  116. struct lws_context;
  117. #define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS)
  118. struct lws_fd_hashtable {
  119. struct lws **wsi;
  120. int length;
  121. };
  122. #ifdef LWS_DLL
  123. #ifdef LWS_INTERNAL
  124. #define LWS_EXTERN extern __declspec(dllexport)
  125. #else
  126. #define LWS_EXTERN extern __declspec(dllimport)
  127. #endif
  128. #else
  129. #define LWS_EXTERN extern
  130. #endif
  131. typedef SOCKET lws_sockfd_type;
  132. typedef HANDLE lws_filefd_type;
  133. #define LWS_WIN32_HANDLE_TYPES
  134. LWS_EXTERN struct lws *
  135. wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd);
  136. LWS_EXTERN int
  137. insert_wsi(struct lws_context *context, struct lws *wsi);
  138. LWS_EXTERN int
  139. delete_from_fd(struct lws_context *context, lws_sockfd_type fd);