1 /* 2 * libwebsockets - small server side websockets and web server implementation 3 * 4 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com> 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 27 #ifndef WIN32_LEAN_AND_MEAN 28 #define WIN32_LEAN_AND_MEAN 29 #endif 30 31 #if defined(WINVER) && (WINVER < 0x0501) 32 #undef WINVER 33 #undef _WIN32_WINNT 34 #define WINVER 0x0501 35 #define _WIN32_WINNT WINVER 36 #endif 37 38 #define LWS_NO_DAEMONIZE 39 #define LWS_ERRNO WSAGetLastError() 40 #define LWS_EAGAIN WSAEWOULDBLOCK 41 #define LWS_EALREADY WSAEALREADY 42 #define LWS_EINPROGRESS WSAEINPROGRESS 43 #define LWS_EINTR WSAEINTR 44 #define LWS_EISCONN WSAEISCONN 45 #define LWS_ENOTCONN WSAENOTCONN 46 #define LWS_EWOULDBLOCK WSAEWOULDBLOCK 47 #define LWS_EADDRINUSE WSAEADDRINUSE 48 #define MSG_NOSIGNAL 0 49 #define SHUT_RDWR SD_BOTH 50 #define SOL_TCP IPPROTO_TCP 51 #define SHUT_WR SD_SEND 52 53 #define compatible_close(fd) closesocket(fd) 54 #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1 55 56 #include <winsock2.h> 57 #include <ws2tcpip.h> 58 #include <windows.h> 59 #include <tchar.h> 60 #ifdef LWS_HAVE_IN6ADDR_H 61 #include <in6addr.h> 62 #endif 63 #include <mstcpip.h> 64 #include <io.h> 65 66 #if !defined(LWS_HAVE_ATOLL) 67 #if defined(LWS_HAVE__ATOI64) 68 #define atoll _atoi64 69 #else 70 #warning No atoll or _atoi64 available, using atoi 71 #define atoll atoi 72 #endif 73 #endif 74 75 #ifndef __func__ 76 #define __func__ __FUNCTION__ 77 #endif 78 79 #ifdef LWS_HAVE__VSNPRINTF 80 #define vsnprintf _vsnprintf 81 #endif 82 83 /* we don't have an implementation for this on windows... */ 84 int kill(int pid, int sig); 85 int fork(void); 86 #ifndef SIGINT 87 #define SIGINT 2 88 #endif 89 90 #include <gettimeofday.h> 91 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 102 #undef __P 103 #ifndef __P 104 #if __STDC__ 105 #define __P(protos) protos 106 #else 107 #define __P(protos) () 108 #endif 109 #endif 110 111 #ifdef _WIN32 112 #ifndef FD_HASHTABLE_MODULUS 113 #define FD_HASHTABLE_MODULUS 32 114 #endif 115 #endif 116 117 #define lws_plat_socket_offset() (0) 118 119 struct lws; 120 struct lws_context; 121 122 #define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS) 123 struct lws_fd_hashtable { 124 struct lws **wsi; 125 int length; 126 }; 127 128 129 #ifdef LWS_DLL 130 #ifdef LWS_INTERNAL 131 #define LWS_EXTERN extern __declspec(dllexport) 132 #else 133 #define LWS_EXTERN extern __declspec(dllimport) 134 #endif 135 #else 136 #define LWS_EXTERN extern 137 #endif 138 139 typedef SOCKET lws_sockfd_type; 140 typedef HANDLE lws_filefd_type; 141 #define LWS_WIN32_HANDLE_TYPES 142 143 LWS_EXTERN struct lws * 144 wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd); 145 146 LWS_EXTERN int 147 insert_wsi(struct lws_context *context, struct lws *wsi); 148 149 LWS_EXTERN int 150 delete_from_fd(struct lws_context *context, lws_sockfd_type fd); 151