private.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * libwebsockets - small server side websockets and web server implementation
  3. *
  4. * Copyright (C) 2010 - 2018 Andy Green <[email protected]>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation:
  9. * version 2.1 of the License.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. * MA 02110-1301 USA
  20. *
  21. * Included from lib/core/private.h if defined(WIN32) || defined(_WIN32)
  22. */
  23. #ifndef WIN32_LEAN_AND_MEAN
  24. #define WIN32_LEAN_AND_MEAN
  25. #endif
  26. #if (WINVER < 0x0501)
  27. #undef WINVER
  28. #undef _WIN32_WINNT
  29. #define WINVER 0x0501
  30. #define _WIN32_WINNT WINVER
  31. #endif
  32. #define LWS_NO_DAEMONIZE
  33. #define LWS_ERRNO WSAGetLastError()
  34. #define LWS_EAGAIN WSAEWOULDBLOCK
  35. #define LWS_EALREADY WSAEALREADY
  36. #define LWS_EINPROGRESS WSAEINPROGRESS
  37. #define LWS_EINTR WSAEINTR
  38. #define LWS_EISCONN WSAEISCONN
  39. #define LWS_ENOTCONN WSAENOTCONN
  40. #define LWS_EWOULDBLOCK WSAEWOULDBLOCK
  41. #define LWS_EADDRINUSE WSAEADDRINUSE
  42. #define MSG_NOSIGNAL 0
  43. #define SHUT_RDWR SD_BOTH
  44. #define SOL_TCP IPPROTO_TCP
  45. #define SHUT_WR SD_SEND
  46. #define compatible_close(fd) closesocket(fd)
  47. #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1
  48. #define LWS_SOCK_INVALID (INVALID_SOCKET)
  49. #include <winsock2.h>
  50. #include <ws2tcpip.h>
  51. #include <windows.h>
  52. #include <tchar.h>
  53. #ifdef LWS_HAVE_IN6ADDR_H
  54. #include <in6addr.h>
  55. #endif
  56. #include <mstcpip.h>
  57. #include <io.h>
  58. #if !defined(LWS_HAVE_ATOLL)
  59. #if defined(LWS_HAVE__ATOI64)
  60. #define atoll _atoi64
  61. #else
  62. #warning No atoll or _atoi64 available, using atoi
  63. #define atoll atoi
  64. #endif
  65. #endif
  66. #ifndef __func__
  67. #define __func__ __FUNCTION__
  68. #endif
  69. #ifdef LWS_HAVE__VSNPRINTF
  70. #define vsnprintf _vsnprintf
  71. #endif
  72. /* we don't have an implementation for this on windows... */
  73. int kill(int pid, int sig);
  74. int fork(void);
  75. #ifndef SIGINT
  76. #define SIGINT 2
  77. #endif
  78. #include <gettimeofday.h>
  79. #ifndef BIG_ENDIAN
  80. #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */
  81. #endif
  82. #ifndef LITTLE_ENDIAN
  83. #define LITTLE_ENDIAN 1234
  84. #endif
  85. #ifndef BYTE_ORDER
  86. #define BYTE_ORDER LITTLE_ENDIAN
  87. #endif
  88. #undef __P
  89. #ifndef __P
  90. #if __STDC__
  91. #define __P(protos) protos
  92. #else
  93. #define __P(protos) ()
  94. #endif
  95. #endif
  96. #ifdef _WIN32
  97. #ifndef FD_HASHTABLE_MODULUS
  98. #define FD_HASHTABLE_MODULUS 32
  99. #endif
  100. #endif
  101. #define lws_plat_socket_offset() (0)
  102. struct lws;
  103. struct lws_context;
  104. #define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS)
  105. struct lws_fd_hashtable {
  106. struct lws **wsi;
  107. int length;
  108. };
  109. #ifdef LWS_DLL
  110. #ifdef LWS_INTERNAL
  111. #define LWS_EXTERN extern __declspec(dllexport)
  112. #else
  113. #define LWS_EXTERN extern __declspec(dllimport)
  114. #endif
  115. #else
  116. #define LWS_EXTERN
  117. #endif
  118. typedef SOCKET lws_sockfd_type;
  119. typedef HANDLE lws_filefd_type;
  120. #define LWS_WIN32_HANDLE_TYPES
  121. LWS_EXTERN struct lws *
  122. wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd);
  123. LWS_EXTERN int
  124. insert_wsi(struct lws_context *context, struct lws *wsi);
  125. LWS_EXTERN int
  126. delete_from_fd(struct lws_context *context, lws_sockfd_type fd);