• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 compatible_file_close(fd) CloseHandle(fd)
55  #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1
56 
57  #include <winsock2.h>
58  #include <ws2tcpip.h>
59  #include <windows.h>
60  #include <tchar.h>
61  #ifdef LWS_HAVE_IN6ADDR_H
62   #include <in6addr.h>
63  #endif
64  #include <mstcpip.h>
65  #include <io.h>
66 
67 #if defined(LWS_WITH_UNIX_SOCK)
68 #include <afunix.h>
69 #endif
70 
71 #if defined(LWS_WITH_TLS)
72 #include <wincrypt.h>
73 #endif
74 
75 #if defined(LWS_HAVE_PTHREAD_H)
76 #define lws_mutex_t		pthread_mutex_t
77 #define lws_mutex_init(x)	pthread_mutex_init(&(x), NULL)
78 #define lws_mutex_destroy(x)	pthread_mutex_destroy(&(x))
79 #define lws_mutex_lock(x)	pthread_mutex_lock(&(x))
80 #define lws_mutex_unlock(x)	pthread_mutex_unlock(&(x))
81 #endif
82 
83  #if !defined(LWS_HAVE_ATOLL)
84   #if defined(LWS_HAVE__ATOI64)
85    #define atoll _atoi64
86   #else
87    #warning No atoll or _atoi64 available, using atoi
88    #define atoll atoi
89   #endif
90  #endif
91 
92  #ifndef __func__
93   #define __func__ __FUNCTION__
94  #endif
95 
96  #ifdef LWS_HAVE__VSNPRINTF
97   #define vsnprintf _vsnprintf
98  #endif
99 
100 /* we don't have an implementation for this on windows... */
101 int kill(int pid, int sig);
102 int fork(void);
103 #ifndef SIGINT
104 #define SIGINT 2
105 #endif
106 
107 #include <gettimeofday.h>
108 
109 #ifndef BIG_ENDIAN
110  #define BIG_ENDIAN    4321  /* to show byte order (taken from gcc) */
111 #endif
112 #ifndef LITTLE_ENDIAN
113  #define LITTLE_ENDIAN 1234
114 #endif
115 #ifndef BYTE_ORDER
116  #define BYTE_ORDER LITTLE_ENDIAN
117 #endif
118 
119 #undef __P
120 #ifndef __P
121  #if __STDC__
122   #define __P(protos) protos
123  #else
124   #define __P(protos) ()
125  #endif
126 #endif
127 
128 #ifdef _WIN32
129  #ifndef FD_HASHTABLE_MODULUS
130   #define FD_HASHTABLE_MODULUS 32
131  #endif
132 #endif
133 
134 #define lws_plat_socket_offset() (0)
135 
136 struct lws;
137 struct lws_context;
138 
139 #define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS)
140 struct lws_fd_hashtable {
141 	struct lws **wsi;
142 	int length;
143 };
144 
145 #if !defined(LWS_EXTERN)
146 #ifdef LWS_DLL
147 #ifdef LWS_INTERNAL
148 #define LWS_EXTERN extern __declspec(dllexport)
149 #else
150 #define LWS_EXTERN extern __declspec(dllimport)
151 #endif
152 #else
153 #define LWS_EXTERN
154 #endif
155 #endif
156 
157 typedef SOCKET lws_sockfd_type;
158 #if defined(__MINGW32__)
159 typedef int lws_filefd_type;
160 #else
161 typedef HANDLE lws_filefd_type;
162 #endif
163 #define LWS_WIN32_HANDLE_TYPES
164 
165 LWS_EXTERN struct lws *
166 wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd);
167 
168 LWS_EXTERN int
169 insert_wsi(struct lws_context *context, struct lws *wsi);
170 
171 LWS_EXTERN int
172 delete_from_fd(struct lws_context *context, lws_sockfd_type fd);
173