autobahn add same serverside rxflow cache to client
[platform/upstream/libwebsockets.git] / lib / private-libwebsockets.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2015 Andy Green <andy@warmcat.com>
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
22 #include "lws_config.h"
23 #include "lws_config_private.h"
24
25 #ifdef LWS_HAVE_SYS_TYPES_H
26 #include <sys/types.h>
27 #endif
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <time.h>
33 #include <ctype.h>
34 #include <limits.h>
35 #include <stdarg.h>
36 #include <assert.h>
37
38 #ifdef LWS_HAVE_SYS_STAT_H
39 #include <sys/stat.h>
40 #endif
41
42 #if defined(WIN32) || defined(_WIN32)
43 #if (WINVER < 0x0501)
44 #undef WINVER
45 #undef _WIN32_WINNT
46 #define WINVER 0x0501
47 #define _WIN32_WINNT WINVER
48 #endif
49 #define LWS_NO_DAEMONIZE
50 #define LWS_ERRNO WSAGetLastError()
51 #define LWS_EAGAIN WSAEWOULDBLOCK
52 #define LWS_EALREADY WSAEALREADY
53 #define LWS_EINPROGRESS WSAEINPROGRESS
54 #define LWS_EINTR WSAEINTR
55 #define LWS_EISCONN WSAEISCONN
56 #define LWS_EWOULDBLOCK WSAEWOULDBLOCK
57 #define LWS_POLLHUP (FD_CLOSE)
58 #define LWS_POLLIN (FD_READ | FD_ACCEPT)
59 #define LWS_POLLOUT (FD_WRITE)
60 #define MSG_NOSIGNAL 0
61 #define SHUT_RDWR SD_BOTH
62 #define SOL_TCP IPPROTO_TCP
63
64 #define compatible_close(fd) closesocket(fd)
65 #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1
66 #define lws_socket_is_valid(x) (!!x)
67 #define LWS_SOCK_INVALID 0
68 #include <winsock2.h>
69 #include <ws2tcpip.h>
70 #include <windows.h>
71 #include <tchar.h>
72 #ifdef LWS_HAVE_IN6ADDR_H
73 #include <in6addr.h>
74 #endif
75 #include <mstcpip.h>
76
77 #ifndef __func__
78 #define __func__ __FUNCTION__
79 #endif
80
81 #ifdef _WIN32_WCE
82 #define vsnprintf _vsnprintf
83 #endif
84
85 #else /* not windows --> */
86
87 #include <fcntl.h>
88 #include <strings.h>
89 #include <unistd.h>
90 #include <sys/types.h>
91 #ifndef MBED_OPERATORS
92 #ifndef __cplusplus
93 #include <errno.h>
94 #endif
95 #include <netdb.h>
96 #include <signal.h>
97 #include <sys/socket.h>
98 #ifdef LWS_BUILTIN_GETIFADDRS
99  #include <getifaddrs.h>
100 #else
101  #include <ifaddrs.h>
102 #endif
103 #if defined (__ANDROID__)
104 #include <syslog.h>
105 #else
106 #include <sys/syslog.h>
107 #endif
108 #include <sys/un.h>
109 #include <sys/socket.h>
110 #include <netdb.h>
111 #include <netinet/in.h>
112 #include <netinet/tcp.h>
113 #include <arpa/inet.h>
114 #include <poll.h>
115 #ifdef LWS_USE_LIBEV
116 #include <ev.h>
117 #endif /* LWS_USE_LIBEV */
118 #include <sys/mman.h>
119
120 #endif /* MBED */
121
122 #ifndef LWS_NO_FORK
123 #ifdef LWS_HAVE_SYS_PRCTL_H
124 #include <sys/prctl.h>
125 #endif
126 #endif
127
128 #include <sys/time.h>
129
130 #define LWS_ERRNO errno
131 #define LWS_EAGAIN EAGAIN
132 #define LWS_EALREADY EALREADY
133 #define LWS_EINPROGRESS EINPROGRESS
134 #define LWS_EINTR EINTR
135 #define LWS_EISCONN EISCONN
136 #define LWS_EWOULDBLOCK EWOULDBLOCK
137 #define LWS_POLLHUP (POLLHUP|POLLERR)
138 #define LWS_POLLIN (POLLIN)
139 #define LWS_POLLOUT (POLLOUT)
140 #define compatible_close(fd) close(fd)
141 #define lws_set_blocking_send(wsi)
142
143 #ifdef MBED_OPERATORS
144 #define lws_socket_is_valid(x) ((x) != NULL)
145 #define LWS_SOCK_INVALID (NULL)
146 #else
147 #define lws_socket_is_valid(x) (x >= 0)
148 #define LWS_SOCK_INVALID (-1)
149 #endif
150 #endif
151
152 #ifndef LWS_HAVE_BZERO
153 #ifndef bzero
154 #define bzero(b, len) (memset((b), '\0', (len)), (void) 0)
155 #endif
156 #endif
157
158 #ifndef LWS_HAVE_STRERROR
159 #define strerror(x) ""
160 #endif
161
162 #ifdef LWS_OPENSSL_SUPPORT
163 #ifdef USE_WOLFSSL
164 #ifdef USE_OLD_CYASSL
165 #include <cyassl/openssl/ssl.h>
166 #include <cyassl/error-ssl.h>
167 #else
168 #include <wolfssl/openssl/ssl.h>
169 #include <wolfssl/error-ssl.h>
170 #endif /* not USE_OLD_CYASSL */
171 #else
172 #include <openssl/ssl.h>
173 #include <openssl/evp.h>
174 #include <openssl/err.h>
175 #include <openssl/md5.h>
176 #include <openssl/sha.h>
177 #endif /* not USE_WOLFSSL */
178 #endif
179
180 #include "libwebsockets.h"
181
182 #if defined(MBED_OPERATORS)
183 #undef compatible_close
184 #define compatible_close(fd) mbed3_delete_tcp_stream_socket(fd)
185 #ifndef BIG_ENDIAN
186 #define BIG_ENDIAN    4321  /* to show byte order (taken from gcc) */
187 #endif
188 #ifndef LITTLE_ENDIAN
189 #define LITTLE_ENDIAN 1234
190 #endif
191 #ifndef BYTE_ORDER
192 #define BYTE_ORDER LITTLE_ENDIAN
193 #endif
194 #endif
195
196 #if defined(WIN32) || defined(_WIN32)
197
198 #ifndef BIG_ENDIAN
199 #define BIG_ENDIAN    4321  /* to show byte order (taken from gcc) */
200 #endif
201 #ifndef LITTLE_ENDIAN
202 #define LITTLE_ENDIAN 1234
203 #endif
204 #ifndef BYTE_ORDER
205 #define BYTE_ORDER LITTLE_ENDIAN
206 #endif
207 #ifndef u_int64_t
208 typedef unsigned __int64 u_int64_t;
209 #endif
210
211 #undef __P
212 #ifndef __P
213 #if __STDC__
214 #define __P(protos) protos
215 #else
216 #define __P(protos) ()
217 #endif
218 #endif
219
220 #else
221
222 #include <sys/stat.h>
223 #include <sys/cdefs.h>
224 #include <sys/time.h>
225
226 #if defined(__APPLE__)
227 #include <machine/endian.h>
228 #elif defined(__FreeBSD__)
229 #include <sys/endian.h>
230 #elif defined(__linux__)
231 #include <endian.h>
232 #endif
233
234 #ifdef __cplusplus
235 extern "C" {
236 #endif
237 #include <stddef.h>
238
239 #ifndef container_of
240 #define container_of(P,T,M)     ((T *)((char *)(P) - offsetof(T, M)))
241 #endif
242
243 #if defined(__QNX__)
244         #include <gulliver.h>
245         #if defined(__LITTLEENDIAN__)
246                 #define BYTE_ORDER __LITTLEENDIAN__
247                 #define LITTLE_ENDIAN __LITTLEENDIAN__
248                 #define BIG_ENDIAN 4321  /* to show byte order (taken from gcc); for suppres warning that BIG_ENDIAN is not defined. */
249         #endif
250         #if defined(__BIGENDIAN__)
251                 #define BYTE_ORDER __BIGENDIAN__
252                 #define LITTLE_ENDIAN 1234  /* to show byte order (taken from gcc); for suppres warning that LITTLE_ENDIAN is not defined. */
253                 #define BIG_ENDIAN __BIGENDIAN__
254         #endif
255 #endif
256
257 #if !defined(BYTE_ORDER)
258 # define BYTE_ORDER __BYTE_ORDER
259 #endif
260 #if !defined(LITTLE_ENDIAN)
261 # define LITTLE_ENDIAN __LITTLE_ENDIAN
262 #endif
263 #if !defined(BIG_ENDIAN)
264 # define BIG_ENDIAN __BIG_ENDIAN
265 #endif
266
267 #endif
268
269 /*
270  * Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag,
271  * but happily have something equivalent in the SO_NOSIGPIPE flag.
272  */
273 #ifdef __APPLE__
274 #define MSG_NOSIGNAL SO_NOSIGPIPE
275 #endif
276
277 #ifdef _WIN32
278 #ifndef FD_HASHTABLE_MODULUS
279 #define FD_HASHTABLE_MODULUS 32
280 #endif
281 #endif
282
283 #ifndef LWS_MAX_HEADER_LEN
284 #define LWS_MAX_HEADER_LEN 1024
285 #endif
286 #ifndef LWS_MAX_HEADER_POOL
287 #define LWS_MAX_HEADER_POOL 16
288 #endif
289 #ifndef LWS_MAX_PROTOCOLS
290 #define LWS_MAX_PROTOCOLS 5
291 #endif
292 #ifndef LWS_MAX_EXTENSIONS_ACTIVE
293 #define LWS_MAX_EXTENSIONS_ACTIVE 3
294 #endif
295 #ifndef SPEC_LATEST_SUPPORTED
296 #define SPEC_LATEST_SUPPORTED 13
297 #endif
298 #ifndef AWAITING_TIMEOUT
299 #define AWAITING_TIMEOUT 5
300 #endif
301 #ifndef CIPHERS_LIST_STRING
302 #define CIPHERS_LIST_STRING "DEFAULT"
303 #endif
304 #ifndef LWS_SOMAXCONN
305 #define LWS_SOMAXCONN SOMAXCONN
306 #endif
307
308 #define MAX_WEBSOCKET_04_KEY_LEN 128
309 #define LWS_MAX_SOCKET_IO_BUF 4096
310
311 #ifndef SYSTEM_RANDOM_FILEPATH
312 #define SYSTEM_RANDOM_FILEPATH "/dev/urandom"
313 #endif
314 #ifndef LWS_MAX_ZLIB_CONN_BUFFER
315 #define LWS_MAX_ZLIB_CONN_BUFFER (64 * 1024)
316 #endif
317
318 /*
319  * if not in a connection storm, check for incoming
320  * connections this many normal connection services
321  */
322 #define LWS_lserv_mod 10
323
324 enum lws_websocket_opcodes_07 {
325         LWSWSOPC_CONTINUATION = 0,
326         LWSWSOPC_TEXT_FRAME = 1,
327         LWSWSOPC_BINARY_FRAME = 2,
328
329         LWSWSOPC_NOSPEC__MUX = 7,
330
331         /* control extensions 8+ */
332
333         LWSWSOPC_CLOSE = 8,
334         LWSWSOPC_PING = 9,
335         LWSWSOPC_PONG = 0xa,
336 };
337
338
339 enum lws_connection_states {
340         LWSS_HTTP,
341         LWSS_HTTP_ISSUING_FILE,
342         LWSS_HTTP_HEADERS,
343         LWSS_HTTP_BODY,
344         LWSS_DEAD_SOCKET,
345         LWSS_ESTABLISHED,
346         LWSS_CLIENT_UNCONNECTED,
347         LWSS_RETURNED_CLOSE_ALREADY,
348         LWSS_AWAITING_CLOSE_ACK,
349         LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE,
350
351         LWSS_HTTP2_AWAIT_CLIENT_PREFACE,
352         LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS,
353         LWSS_HTTP2_ESTABLISHED,
354 };
355
356 enum http_version {
357         HTTP_VERSION_1_0,
358         HTTP_VERSION_1_1,
359 };
360
361 enum http_connection_type {
362         HTTP_CONNECTION_CLOSE,
363         HTTP_CONNECTION_KEEP_ALIVE
364 };
365
366 enum lws_pending_protocol_send {
367         LWS_PPS_NONE,
368         LWS_PPS_HTTP2_MY_SETTINGS,
369         LWS_PPS_HTTP2_ACK_SETTINGS,
370         LWS_PPS_HTTP2_PONG,
371 };
372
373 enum lws_rx_parse_state {
374         LWS_RXPS_NEW,
375
376         LWS_RXPS_04_MASK_NONCE_1,
377         LWS_RXPS_04_MASK_NONCE_2,
378         LWS_RXPS_04_MASK_NONCE_3,
379
380         LWS_RXPS_04_FRAME_HDR_1,
381         LWS_RXPS_04_FRAME_HDR_LEN,
382         LWS_RXPS_04_FRAME_HDR_LEN16_2,
383         LWS_RXPS_04_FRAME_HDR_LEN16_1,
384         LWS_RXPS_04_FRAME_HDR_LEN64_8,
385         LWS_RXPS_04_FRAME_HDR_LEN64_7,
386         LWS_RXPS_04_FRAME_HDR_LEN64_6,
387         LWS_RXPS_04_FRAME_HDR_LEN64_5,
388         LWS_RXPS_04_FRAME_HDR_LEN64_4,
389         LWS_RXPS_04_FRAME_HDR_LEN64_3,
390         LWS_RXPS_04_FRAME_HDR_LEN64_2,
391         LWS_RXPS_04_FRAME_HDR_LEN64_1,
392
393         LWS_RXPS_07_COLLECT_FRAME_KEY_1,
394         LWS_RXPS_07_COLLECT_FRAME_KEY_2,
395         LWS_RXPS_07_COLLECT_FRAME_KEY_3,
396         LWS_RXPS_07_COLLECT_FRAME_KEY_4,
397
398         LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED
399 };
400
401
402 enum connection_mode {
403         LWSCM_HTTP_SERVING,
404         LWSCM_HTTP_SERVING_ACCEPTED, /* actual HTTP service going on */
405         LWSCM_PRE_WS_SERVING_ACCEPT,
406
407         LWSCM_WS_SERVING,
408         LWSCM_WS_CLIENT,
409
410         LWSCM_HTTP2_SERVING,
411
412         /* transient, ssl delay hiding */
413         LWSCM_SSL_ACK_PENDING,
414
415         /* transient modes */
416         LWSCM_WSCL_WAITING_CONNECT,
417         LWSCM_WSCL_WAITING_PROXY_REPLY,
418         LWSCM_WSCL_ISSUE_HANDSHAKE,
419         LWSCM_WSCL_ISSUE_HANDSHAKE2,
420         LWSCM_WSCL_WAITING_SSL,
421         LWSCM_WSCL_WAITING_SERVER_REPLY,
422         LWSCM_WSCL_WAITING_EXTENSION_CONNECT,
423         LWSCM_WSCL_PENDING_CANDIDATE_CHILD,
424
425         /* special internal types */
426         LWSCM_SERVER_LISTENER,
427 };
428
429 enum {
430         LWS_RXFLOW_ALLOW = (1 << 0),
431         LWS_RXFLOW_PENDING_CHANGE = (1 << 1),
432 };
433
434 /* this is not usable directly by user code any more, lws_close_reason() */
435 #define LWS_WRITE_CLOSE 4
436
437 struct lws_protocols;
438 struct lws;
439
440 #ifdef LWS_USE_LIBEV
441 struct lws_io_watcher {
442         struct ev_io watcher;
443         struct lws_context* context;
444 };
445
446 struct lws_signal_watcher {
447         struct ev_signal watcher;
448         struct lws_context* context;
449 };
450 #endif /* LWS_USE_LIBEV */
451
452 #ifdef _WIN32
453 #define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS)
454 struct lws_fd_hashtable {
455         struct lws **wsi;
456         int length;
457 };
458 #endif
459
460 /*
461  * This is totally opaque to code using the library.  It's exported as a
462  * forward-reference pointer-only declaration; the user can use the pointer with
463  * other APIs to get information out of it.
464  */
465
466 struct lws_fragments {
467         unsigned short offset;
468         unsigned short len;
469         unsigned char nfrag; /* which ah->frag[] continues this content, or 0 */
470 };
471
472 /*
473  * these are assigned from a pool held in the context.
474  * Both client and server mode uses them for http header analysis
475  */
476
477 struct allocated_headers {
478         char *data; /* prepared by context init to point to dedicated storage */
479         /*
480          * the randomly ordered fragments, indexed by frag_index and
481          * lws_fragments->nfrag for continuation.
482          */
483         struct lws_fragments frags[WSI_TOKEN_COUNT * 2];
484         /*
485          * for each recognized token, frag_index says which frag[] his data
486          * starts in (0 means the token did not appear)
487          * the actual header data gets dumped as it comes in, into data[]
488          */
489         unsigned char frag_index[WSI_TOKEN_COUNT];
490 #ifndef LWS_NO_CLIENT
491         char initial_handshake_hash_base64[30];
492         unsigned short c_port;
493 #endif
494
495         unsigned short pos;
496         unsigned char in_use;
497         unsigned char nfrag;
498 };
499
500 struct lws_context {
501         time_t last_timeout_check_s;
502         struct lws_plat_file_ops fops;
503 #ifdef _WIN32
504         WSAEVENT *events;
505 #endif
506         struct lws_pollfd *fds;
507 #ifdef _WIN32
508 /* different implementation between unix and windows */
509         struct lws_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS];
510 #else
511         struct lws **lws_lookup;  /* fd to wsi */
512 #endif
513 #ifdef LWS_USE_LIBEV
514         struct ev_loop* io_loop;
515         struct lws_io_watcher w_accept;
516         struct lws_signal_watcher w_sigint;
517         lws_ev_signal_cb* lws_ev_sigint_cb;
518 #endif /* LWS_USE_LIBEV */
519         const char *iface;
520         const struct lws_token_limits *token_limits;
521         void *user_space;
522 #ifndef LWS_NO_SERVER
523         struct lws *wsi_listening;
524 #endif
525         const struct lws_protocols *protocols;
526         void *http_header_data;
527         struct allocated_headers *ah_pool;
528 #ifdef LWS_OPENSSL_SUPPORT
529         SSL_CTX *ssl_ctx;
530         SSL_CTX *ssl_client_ctx;
531         struct lws *pending_read_list; /* linked list */
532 #endif
533 #ifndef LWS_NO_EXTENSIONS
534         const struct lws_extension *extensions;
535 #endif
536
537         /*
538          * usable by anything in the service code, but only if the scope
539          * does not last longer than the service action (since next service
540          * of any socket can likewise use it and overwrite)
541          */
542         unsigned char serv_buf[LWS_MAX_SOCKET_IO_BUF];
543         char http_proxy_address[128];
544         char proxy_basic_auth_token[128];
545         char canonical_hostname[128];
546 #ifdef LWS_LATENCY
547         unsigned long worst_latency;
548         char worst_latency_info[256];
549 #endif
550
551         lws_sockfd_type lserv_fd;
552
553         int fds_count;
554         int max_fds;
555         int listen_port;
556 #ifdef LWS_USE_LIBEV
557         int use_ev_sigint;
558 #endif
559         int started_with_parent;
560
561         int fd_random;
562         int lserv_mod;
563         int lserv_count;
564         int lserv_seen;
565         unsigned int http_proxy_port;
566         unsigned int options;
567
568         /*
569          * set to the Thread ID that's doing the service loop just before entry
570          * to poll indicates service thread likely idling in poll()
571          * volatile because other threads may check it as part of processing
572          * for pollfd event change.
573          */
574         volatile int service_tid;
575         int service_tid_detected;
576 #ifndef _WIN32
577         int dummy_pipe_fds[2];
578 #endif
579
580         int count_protocols;
581         int ka_time;
582         int ka_probes;
583         int ka_interval;
584
585 #ifdef LWS_OPENSSL_SUPPORT
586         int use_ssl;
587         int allow_non_ssl_on_ssl_port;
588         unsigned int user_supplied_ssl_ctx:1;
589 #define lws_ssl_anybody_has_buffered_read(ctx) \
590                 (ctx->use_ssl && ctx->pending_read_list)
591 #else
592 #define lws_ssl_anybody_has_buffered_read(ctx) (0)
593 #endif
594
595         short max_http_header_data;
596         short max_http_header_pool;
597         short ah_count_in_use;
598 };
599
600 enum {
601         LWS_EV_READ = (1 << 0),
602         LWS_EV_WRITE = (1 << 1),
603         LWS_EV_START = (1 << 2),
604         LWS_EV_STOP = (1 << 3),
605 };
606
607 #ifdef LWS_USE_LIBEV
608 #define LWS_LIBEV_ENABLED(context) (context->options & LWS_SERVER_OPTION_LIBEV)
609 LWS_EXTERN void lws_feature_status_libev(struct lws_context_creation_info *info);
610 LWS_EXTERN void
611 lws_libev_accept(struct lws *new_wsi, lws_sockfd_type accept_fd);
612 LWS_EXTERN void
613 lws_libev_io(struct lws *wsi, int flags);
614 LWS_EXTERN int
615 lws_libev_init_fd_table(struct lws_context *context);
616 LWS_EXTERN void
617 lws_libev_run(const struct lws_context *context);
618 #else
619 #define LWS_LIBEV_ENABLED(context) (0)
620 #ifdef LWS_POSIX
621 #define lws_feature_status_libev(_a) \
622                         lwsl_notice("libev support not compiled in\n")
623 #else
624 #define lws_feature_status_libev(_a)
625 #endif
626 #define lws_libev_accept(_a, _b) ((void) 0)
627 #define lws_libev_io(_a, _b) ((void) 0)
628 #define lws_libev_init_fd_table(_a) (0)
629 #define lws_libev_run(_a) ((void) 0)
630 #endif
631
632 #ifdef LWS_USE_IPV6
633 #define LWS_IPV6_ENABLED(context) \
634         (!(context->options & LWS_SERVER_OPTION_DISABLE_IPV6))
635 #else
636 #define LWS_IPV6_ENABLED(context) (0)
637 #endif
638
639 enum uri_path_states {
640         URIPS_IDLE,
641         URIPS_SEEN_SLASH,
642         URIPS_SEEN_SLASH_DOT,
643         URIPS_SEEN_SLASH_DOT_DOT,
644 };
645
646 enum uri_esc_states {
647         URIES_IDLE,
648         URIES_SEEN_PERCENT,
649         URIES_SEEN_PERCENT_H1,
650 };
651
652 /* notice that these union members:
653  *
654  *  hdr
655  *  http
656  *  http2
657  *
658  * all have a pointer to allocated_headers struct as their first member.
659  *
660  * It means for allocated_headers access, the three union paths can all be
661  * used interchangeably to access the same data
662  */
663
664 struct _lws_http_mode_related {
665         /* MUST be first in struct */
666         struct allocated_headers *ah; /* mirroring  _lws_header_related */
667         unsigned long filepos;
668         unsigned long filelen;
669         lws_filefd_type fd;
670
671         enum http_version request_version;
672         enum http_connection_type connection_type;
673         unsigned int content_length;
674         unsigned int content_remain;
675 };
676
677 #ifdef LWS_USE_HTTP2
678
679 enum lws_http2_settings {
680         LWS_HTTP2_SETTINGS__HEADER_TABLE_SIZE = 1,
681         LWS_HTTP2_SETTINGS__ENABLE_PUSH,
682         LWS_HTTP2_SETTINGS__MAX_CONCURRENT_STREAMS,
683         LWS_HTTP2_SETTINGS__INITIAL_WINDOW_SIZE,
684         LWS_HTTP2_SETTINGS__MAX_FRAME_SIZE,
685         LWS_HTTP2_SETTINGS__MAX_HEADER_LIST_SIZE,
686
687         LWS_HTTP2_SETTINGS__COUNT /* always last */
688 };
689
690 enum lws_http2_wellknown_frame_types {
691         LWS_HTTP2_FRAME_TYPE_DATA,
692         LWS_HTTP2_FRAME_TYPE_HEADERS,
693         LWS_HTTP2_FRAME_TYPE_PRIORITY,
694         LWS_HTTP2_FRAME_TYPE_RST_STREAM,
695         LWS_HTTP2_FRAME_TYPE_SETTINGS,
696         LWS_HTTP2_FRAME_TYPE_PUSH_PROMISE,
697         LWS_HTTP2_FRAME_TYPE_PING,
698         LWS_HTTP2_FRAME_TYPE_GOAWAY,
699         LWS_HTTP2_FRAME_TYPE_WINDOW_UPDATE,
700         LWS_HTTP2_FRAME_TYPE_CONTINUATION,
701
702         LWS_HTTP2_FRAME_TYPE_COUNT /* always last */
703 };
704
705 enum lws_http2_flags {
706         LWS_HTTP2_FLAG_END_STREAM = 1,
707         LWS_HTTP2_FLAG_END_HEADERS = 4,
708         LWS_HTTP2_FLAG_PADDED = 8,
709         LWS_HTTP2_FLAG_PRIORITY = 0x20,
710
711         LWS_HTTP2_FLAG_SETTINGS_ACK = 1,
712 };
713
714 #define LWS_HTTP2_STREAM_ID_MASTER 0
715 #define LWS_HTTP2_FRAME_HEADER_LENGTH 9
716 #define LWS_HTTP2_SETTINGS_LENGTH 6
717
718 struct http2_settings {
719         unsigned int setting[LWS_HTTP2_SETTINGS__COUNT];
720 };
721
722 enum http2_hpack_state {
723
724         /* optional before first header block */
725         HPKS_OPT_PADDING,
726         HKPS_OPT_E_DEPENDENCY,
727         HKPS_OPT_WEIGHT,
728
729         /* header block */
730         HPKS_TYPE,
731
732         HPKS_IDX_EXT,
733
734         HPKS_HLEN,
735         HPKS_HLEN_EXT,
736
737         HPKS_DATA,
738
739         /* optional after last header block */
740         HKPS_OPT_DISCARD_PADDING,
741 };
742
743 enum http2_hpack_type {
744         HPKT_INDEXED_HDR_7,
745         HPKT_INDEXED_HDR_6_VALUE_INCR,
746         HPKT_LITERAL_HDR_VALUE_INCR,
747         HPKT_INDEXED_HDR_4_VALUE,
748         HPKT_LITERAL_HDR_VALUE,
749         HPKT_SIZE_5
750 };
751
752 struct hpack_dt_entry {
753         int token; /* additions that don't map to a token are ignored */
754         int arg_offset;
755         int arg_len;
756 };
757
758 struct hpack_dynamic_table {
759         struct hpack_dt_entry *entries;
760         char *args;
761         int pos;
762         int next;
763         int num_entries;
764         int args_length;
765 };
766
767 struct _lws_http2_related {
768         /*
769          * having this first lets us also re-use all HTTP union code
770          * and in turn, http_mode_related has allocated headers in right
771          * place so we can use the header apis on the wsi directly still
772          */
773         struct _lws_http_mode_related http; /* MUST BE FIRST IN STRUCT */
774
775         struct http2_settings my_settings;
776         struct http2_settings peer_settings;
777
778         struct lws *parent_wsi;
779         struct lws *next_child_wsi;
780
781         struct hpack_dynamic_table *hpack_dyn_table;
782         struct lws *stream_wsi;
783         unsigned char ping_payload[8];
784         unsigned char one_setting[LWS_HTTP2_SETTINGS_LENGTH];
785
786         unsigned int count;
787         unsigned int length;
788         unsigned int stream_id;
789         enum http2_hpack_state hpack;
790         enum http2_hpack_type hpack_type;
791         unsigned int header_index;
792         unsigned int hpack_len;
793         unsigned int hpack_e_dep;
794         int tx_credit;
795         unsigned int my_stream_id;
796         unsigned int child_count;
797         int my_priority;
798         
799         unsigned int END_STREAM:1;
800         unsigned int END_HEADERS:1;
801         unsigned int send_END_STREAM:1;
802         unsigned int GOING_AWAY;
803         unsigned int requested_POLLOUT:1;
804         unsigned int waiting_tx_credit:1;
805         unsigned int huff:1;
806         unsigned int value:1;
807
808         unsigned short round_robin_POLLOUT;
809         unsigned short count_POLLOUT_children;
810         unsigned short hpack_pos;
811
812         unsigned char type;
813         unsigned char flags;
814         unsigned char frame_state;
815         unsigned char padding;
816         unsigned char hpack_m;
817         unsigned char initialized;
818 };
819
820 #define HTTP2_IS_TOPLEVEL_WSI(wsi) (!wsi->u.http2.parent_wsi)
821
822 #endif
823
824 struct _lws_header_related {
825         /* MUST be first in struct */
826         struct allocated_headers *ah;
827         enum uri_path_states ups;
828         enum uri_esc_states ues;
829         short lextable_pos;
830         unsigned short current_token_limit;
831         char esc_stash;
832         char post_literal_equal;
833         unsigned char parser_state; /* enum lws_token_indexes */
834 };
835
836 struct _lws_websocket_related {
837         char *rx_user_buffer;
838         size_t rx_packet_length;
839         unsigned int rx_user_buffer_head;
840         unsigned char mask_nonce[4];
841         /* Also used for close content... control opcode == < 128 */
842         unsigned char ping_payload_buf[128 - 3 + LWS_SEND_BUFFER_PRE_PADDING];
843
844         unsigned char ping_payload_len;
845         unsigned char frame_mask_index;
846         unsigned char opcode;
847         unsigned char rsv;
848         /* zero if no info, or length including 2-byte close code */
849         unsigned char close_in_ping_buffer_len;
850
851         unsigned int final:1;
852         unsigned int frame_is_binary:1;
853         unsigned int all_zero_nonce:1;
854         unsigned int this_frame_masked:1;
855         unsigned int inside_frame:1; /* next write will be more of frame */
856         unsigned int clean_buffer:1; /* buffer not rewritten by extension */
857         unsigned int payload_is_close:1; /* process as PONG, but it is close */
858         unsigned int ping_pending_flag:1;
859 };
860
861 struct lws {
862
863         /* structs */
864         /* members with mutually exclusive lifetimes are unionized */
865
866         union u {
867                 struct _lws_http_mode_related http;
868 #ifdef LWS_USE_HTTP2
869                 struct _lws_http2_related http2;
870 #endif
871                 struct _lws_header_related hdr;
872                 struct _lws_websocket_related ws;
873         } u;
874
875         /* lifetime members */
876
877 #ifdef LWS_USE_LIBEV
878         struct lws_io_watcher w_read;
879         struct lws_io_watcher w_write;
880 #endif /* LWS_USE_LIBEV */
881         time_t pending_timeout_limit;
882
883         /* pointers */
884
885         struct lws_context *context;
886         const struct lws_protocols *protocol;
887         void *user_space;
888         /* rxflow handling */
889         unsigned char *rxflow_buffer;
890         /* truncated send handling */
891         unsigned char *trunc_alloc; /* non-NULL means buffering in progress */
892 #ifndef LWS_NO_EXTENSIONS
893         const struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
894         void *active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE];
895 #endif
896 #ifdef LWS_OPENSSL_SUPPORT
897         SSL *ssl;
898         BIO *client_bio;
899         struct lws *pending_read_list_prev, *pending_read_list_next;
900 #endif
901 #ifdef LWS_LATENCY
902         unsigned long action_start;
903         unsigned long latency_start;
904 #endif
905         /* pointer / int */
906         lws_sockfd_type sock;
907
908         /* ints */
909         enum lws_pending_protocol_send pps;
910         int position_in_fds_table;
911         int rxflow_len;
912         int rxflow_pos;
913         unsigned int trunc_alloc_len; /* size of malloc */
914         unsigned int trunc_offset; /* where we are in terms of spilling */
915         unsigned int trunc_len; /* how much is buffered */
916
917         unsigned int hdr_parsing_completed:1;
918         unsigned int user_space_externally_allocated:1;
919         unsigned int socket_is_permanently_unusable:1;
920         unsigned int rxflow_change_to:2;
921 #ifndef LWS_NO_EXTENSIONS
922         unsigned int extension_data_pending:1;
923 #endif
924 #ifdef LWS_OPENSSL_SUPPORT
925         unsigned int use_ssl:2;
926         unsigned int upgraded:1;
927 #endif
928 #ifdef _WIN32
929         unsigned int sock_send_blocking:1;
930 #endif
931
932         /* chars */
933 #ifndef LWS_NO_EXTENSIONS
934         unsigned char count_active_extensions;
935 #endif
936         unsigned char ietf_spec_revision;
937         char mode; /* enum connection_mode */
938         char state; /* enum lws_connection_states */
939         char lws_rx_parse_state; /* enum lws_rx_parse_state */
940         char rx_frame_type; /* enum lws_write_protocol */
941         char pending_timeout; /* enum pending_timeout */
942 };
943
944 LWS_EXTERN int log_level;
945
946 LWS_EXTERN void
947 lws_close_free_wsi(struct lws *wsi, enum lws_close_status);
948
949 LWS_EXTERN int
950 remove_wsi_socket_from_fds(struct lws *wsi);
951 LWS_EXTERN int
952 lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len);
953
954 #ifndef LWS_LATENCY
955 static inline void
956 lws_latency(struct lws_context *context, struct lws *wsi, const char *action,
957             int ret, int completion) {
958         do {
959                 (void)context; (void)wsi; (void)action; (void)ret;
960                 (void)completion;
961         } while (0);
962 }
963 static inline void
964 lws_latency_pre(struct lws_context *context, struct lws *wsi) {
965         do { (void)context; (void)wsi; } while (0);
966 }
967 #else
968 #define lws_latency_pre(_context, _wsi) lws_latency(_context, _wsi, NULL, 0, 0)
969 extern void
970 lws_latency(struct lws_context *context, struct lws *wsi, const char *action,
971             int ret, int completion);
972 #endif
973
974 LWS_EXTERN void
975 lws_set_protocol_write_pending(struct lws *wsi,
976                                enum lws_pending_protocol_send pend);
977 LWS_EXTERN int
978 lws_client_rx_sm(struct lws *wsi, unsigned char c);
979
980 LWS_EXTERN int
981 lws_parse(struct lws *wsi, unsigned char c);
982
983 LWS_EXTERN int
984 lws_http_action(struct lws *wsi);
985
986 LWS_EXTERN int
987 lws_b64_selftest(void);
988
989 #if defined(_WIN32) || defined(MBED_OPERATORS)
990 LWS_EXTERN struct lws *
991 wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd);
992
993 LWS_EXTERN int
994 insert_wsi(struct lws_context *context, struct lws *wsi);
995
996 LWS_EXTERN int
997 delete_from_fd(struct lws_context *context, lws_sockfd_type fd);
998 #else
999 #define wsi_from_fd(A,B)  A->lws_lookup[B]
1000 #define insert_wsi(A,B)   A->lws_lookup[B->sock]=B
1001 #define delete_from_fd(A,B) A->lws_lookup[B]=0
1002 #endif
1003
1004 LWS_EXTERN int
1005 insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi);
1006
1007 LWS_EXTERN int
1008 lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len);
1009
1010
1011 LWS_EXTERN int
1012 lws_service_timeout_check(struct lws *wsi, unsigned int sec);
1013
1014 LWS_EXTERN struct lws *
1015 lws_client_connect_2(struct lws *wsi);
1016
1017 LWS_EXTERN struct lws *
1018 lws_create_new_server_wsi(struct lws_context *context);
1019
1020 LWS_EXTERN char *
1021 lws_generate_client_handshake(struct lws *wsi, char *pkt);
1022
1023 LWS_EXTERN int
1024 lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd);
1025
1026 /*
1027  * EXTENSIONS
1028  */
1029
1030 #ifndef LWS_NO_EXTENSIONS
1031 LWS_VISIBLE void
1032 lws_context_init_extensions(struct lws_context_creation_info *info,
1033                             struct lws_context *context);
1034 LWS_EXTERN int
1035 lws_any_extension_handled(struct lws *wsi,
1036                           enum lws_extension_callback_reasons r,
1037                           void *v, size_t len);
1038
1039 LWS_EXTERN int
1040 lws_ext_cb_wsi_active_exts(struct lws *wsi, int reason,
1041                                  void *buf, int len);
1042 LWS_EXTERN int
1043 lws_ext_cb_all_exts(struct lws_context *context,
1044                                          struct lws *wsi, int reason,
1045                                          void *arg, int len);
1046 #else
1047 #define lws_any_extension_handled(_a, _b, _c, _d) (0)
1048 #define lws_ext_cb_wsi_active_exts(_a, _b, _c, _d) (0)
1049 #define lws_ext_cb_all_exts(_a, _b, _c, _d, _e) (0)
1050 #define lws_issue_raw_ext_access lws_issue_raw
1051 #define lws_context_init_extensions(_a, _b)
1052 #endif
1053
1054 LWS_EXTERN int
1055 lws_client_interpret_server_handshake(struct lws *wsi);
1056
1057 LWS_EXTERN int
1058 lws_rx_sm(struct lws *wsi, unsigned char c);
1059
1060 LWS_EXTERN int
1061 lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len);
1062
1063 LWS_EXTERN void
1064 lws_union_transition(struct lws *wsi, enum connection_mode mode);
1065
1066 LWS_EXTERN int
1067 user_callback_handle_rxflow(callback_function, struct lws *wsi,
1068                             enum lws_callback_reasons reason, void *user,
1069                             void *in, size_t len);
1070 #ifdef LWS_USE_HTTP2
1071 LWS_EXTERN struct lws *lws_http2_get_network_wsi(struct lws *wsi);
1072 struct lws * lws_http2_get_nth_child(struct lws *wsi, int n);
1073 LWS_EXTERN int
1074 lws_http2_interpret_settings_payload(struct http2_settings *settings,
1075                                      unsigned char *buf, int len);
1076 LWS_EXTERN void lws_http2_init(struct http2_settings *settings);
1077 LWS_EXTERN int
1078 lws_http2_parser(struct lws *wsi, unsigned char c);
1079 LWS_EXTERN int lws_http2_do_pps_send(struct lws_context *context,
1080                                      struct lws *wsi);
1081 LWS_EXTERN int lws_http2_frame_write(struct lws *wsi, int type, int flags,
1082                                      unsigned int sid, unsigned int len,
1083                                      unsigned char *buf);
1084 LWS_EXTERN struct lws *
1085 lws_http2_wsi_from_id(struct lws *wsi, unsigned int sid);
1086 LWS_EXTERN int lws_hpack_interpret(struct lws *wsi,
1087                                    unsigned char c);
1088 LWS_EXTERN int
1089 lws_add_http2_header_by_name(struct lws *wsi,
1090                              const unsigned char *name,
1091                              const unsigned char *value, int length,
1092                              unsigned char **p, unsigned char *end);
1093 LWS_EXTERN int
1094 lws_add_http2_header_by_token(struct lws *wsi,
1095                             enum lws_token_indexes token,
1096                             const unsigned char *value, int length,
1097                             unsigned char **p, unsigned char *end);
1098 LWS_EXTERN int
1099 lws_add_http2_header_status(struct lws *wsi,
1100                             unsigned int code, unsigned char **p,
1101                             unsigned char *end);
1102 LWS_EXTERN
1103 void lws_http2_configure_if_upgraded(struct lws *wsi);
1104 #else
1105 #define lws_http2_configure_if_upgraded(x)
1106 #endif
1107
1108 LWS_EXTERN int
1109 lws_plat_set_socket_options(struct lws_context *context, lws_sockfd_type fd);
1110
1111 LWS_EXTERN int
1112 lws_allocate_header_table(struct lws *wsi);
1113
1114 LWS_EXTERN int
1115 lws_free_header_table(struct lws *wsi);
1116
1117 LWS_EXTERN char *
1118 lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h);
1119
1120 LWS_EXTERN int
1121 lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s);
1122
1123 LWS_EXTERN int
1124 lws_ensure_user_space(struct lws *wsi);
1125
1126 LWS_EXTERN int
1127 lws_change_pollfd(struct lws *wsi, int _and, int _or);
1128
1129 #ifndef LWS_NO_SERVER
1130 int lws_context_init_server(struct lws_context_creation_info *info,
1131                             struct lws_context *context);
1132 LWS_EXTERN int
1133 handshake_0405(struct lws_context *context, struct lws *wsi);
1134 LWS_EXTERN int
1135 lws_interpret_incoming_packet(struct lws *wsi, unsigned char *buf, size_t len);
1136 LWS_EXTERN void
1137 lws_server_get_canonical_hostname(struct lws_context *context,
1138                                   struct lws_context_creation_info *info);
1139 #else
1140 #define lws_context_init_server(_a, _b) (0)
1141 #define lws_interpret_incoming_packet(_a, _b, _c) (0)
1142 #define lws_server_get_canonical_hostname(_a, _b)
1143 #endif
1144
1145 #ifndef LWS_NO_DAEMONIZE
1146 LWS_EXTERN int get_daemonize_pid();
1147 #else
1148 #define get_daemonize_pid() (0)
1149 #endif
1150
1151 #if !defined(MBED_OPERATORS)
1152 LWS_EXTERN int
1153 interface_to_sa(struct lws_context *context, const char *ifname,
1154                 struct sockaddr_in *addr, size_t addrlen);
1155 #endif
1156 LWS_EXTERN void lwsl_emit_stderr(int level, const char *line);
1157
1158 enum lws_ssl_capable_status {
1159         LWS_SSL_CAPABLE_ERROR = -1,
1160         LWS_SSL_CAPABLE_MORE_SERVICE = -2,
1161 };
1162
1163 #ifndef LWS_OPENSSL_SUPPORT
1164 #define LWS_SSL_ENABLED(context) (0)
1165 #define lws_context_init_server_ssl(_a, _b) (0)
1166 #define lws_ssl_destroy(_a)
1167 #define lws_context_init_http2_ssl(_a)
1168 #define lws_ssl_capable_read lws_ssl_capable_read_no_ssl
1169 #define lws_ssl_capable_write lws_ssl_capable_write_no_ssl
1170 #define lws_ssl_pending lws_ssl_pending_no_ssl
1171 #define lws_server_socket_service_ssl(_a, _b, _c, _d) (0)
1172 #define lws_ssl_close(_a) (0)
1173 #define lws_ssl_context_destroy(_a)
1174 #define lws_ssl_remove_wsi_from_buffered_list(_a)
1175 #else
1176 #define LWS_SSL_ENABLED(context) (context->use_ssl)
1177 LWS_EXTERN int openssl_websocket_private_data_index;
1178 LWS_EXTERN int
1179 lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len);
1180 LWS_EXTERN int
1181 lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len);
1182 LWS_EXTERN int
1183 lws_ssl_pending(struct lws *wsi);
1184 LWS_EXTERN int
1185 lws_server_socket_service_ssl(struct lws **wsi, struct lws *new_wsi,
1186                               lws_sockfd_type accept_fd,
1187                               struct lws_pollfd *pollfd);
1188 LWS_EXTERN int
1189 lws_ssl_close(struct lws *wsi);
1190 LWS_EXTERN void
1191 lws_ssl_context_destroy(struct lws_context *context);
1192 LWS_VISIBLE void
1193 lws_ssl_remove_wsi_from_buffered_list(struct lws *wsi);
1194 #ifndef LWS_NO_SERVER
1195 LWS_EXTERN int
1196 lws_context_init_server_ssl(struct lws_context_creation_info *info,
1197                             struct lws_context *context);
1198 #else
1199 #define lws_context_init_server_ssl(_a, _b) (0)
1200 #endif
1201 LWS_EXTERN void
1202 lws_ssl_destroy(struct lws_context *context);
1203
1204 /* HTTP2-related */
1205
1206 #ifdef LWS_USE_HTTP2
1207 LWS_EXTERN void
1208 lws_context_init_http2_ssl(struct lws_context *context);
1209 #else
1210 #define lws_context_init_http2_ssl(_a)
1211 #endif
1212 #endif
1213
1214 LWS_EXTERN int
1215 lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len);
1216
1217 LWS_EXTERN int
1218 lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len);
1219
1220 LWS_EXTERN int
1221 lws_ssl_pending_no_ssl(struct lws *wsi);
1222
1223 #ifndef LWS_NO_CLIENT
1224 LWS_EXTERN int lws_client_socket_service(struct lws_context *context,
1225                                          struct lws *wsi,
1226                                          struct lws_pollfd *pollfd);
1227 #ifdef LWS_OPENSSL_SUPPORT
1228 LWS_EXTERN int
1229 lws_context_init_client_ssl(struct lws_context_creation_info *info,
1230                             struct lws_context *context);
1231 #else
1232         #define lws_context_init_client_ssl(_a, _b) (0)
1233 #endif
1234 LWS_EXTERN int
1235 lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len);
1236 LWS_EXTERN void
1237 lws_decode_ssl_error(void);
1238 #else
1239 #define lws_context_init_client_ssl(_a, _b) (0)
1240 #define lws_handshake_client(_a, _b, _c) (0)
1241 #endif
1242
1243 LWS_EXTERN int
1244 _lws_rx_flow_control(struct lws *wsi);
1245
1246 #ifndef LWS_NO_SERVER
1247 LWS_EXTERN int
1248 lws_server_socket_service(struct lws_context *context, struct lws *wsi,
1249                           struct lws_pollfd *pollfd);
1250 LWS_EXTERN int
1251 lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len);
1252 LWS_EXTERN int
1253 _lws_server_listen_accept_flow_control(struct lws_context *context, int on);
1254 #else
1255 #define lws_server_socket_service(_a, _b, _c) (0)
1256 #define lws_handshake_server(_a, _b, _c) (0)
1257 #define _lws_server_listen_accept_flow_control(a, b) (0)
1258 #endif
1259
1260 LWS_EXTERN int
1261 lws_get_addresses(struct lws_context *context, void *ads, char *name,
1262                   int name_len, char *rip, int rip_len);
1263
1264 /*
1265  * custom allocator
1266  */
1267 LWS_EXTERN void*
1268 lws_realloc(void *ptr, size_t size);
1269
1270 LWS_EXTERN void*
1271 lws_zalloc(size_t size);
1272
1273 #define lws_malloc(S)   lws_realloc(NULL, S)
1274 #define lws_free(P)     lws_realloc(P, 0)
1275 #define lws_free_set_NULL(P)    do { lws_realloc(P, 0); (P) = NULL; } while(0)
1276
1277 /* lws_plat_ */
1278 LWS_EXTERN void
1279 lws_plat_delete_socket_from_fds(struct lws_context *context,
1280                                 struct lws *wsi, int m);
1281 LWS_EXTERN void
1282 lws_plat_insert_socket_into_fds(struct lws_context *context,
1283                                 struct lws *wsi);
1284 LWS_EXTERN void
1285 lws_plat_service_periodic(struct lws_context *context);
1286
1287 LWS_EXTERN int
1288 lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi,
1289                        struct lws_pollfd *pfd);
1290 LWS_EXTERN int
1291 lws_plat_context_early_init(void);
1292 LWS_EXTERN void
1293 lws_plat_context_early_destroy(struct lws_context *context);
1294 LWS_EXTERN void
1295 lws_plat_context_late_destroy(struct lws_context *context);
1296 LWS_EXTERN int
1297 lws_poll_listen_fd(struct lws_pollfd *fd);
1298 LWS_EXTERN int
1299 lws_plat_service(struct lws_context *context, int timeout_ms);
1300 LWS_EXTERN int
1301 lws_plat_init(struct lws_context *context,
1302               struct lws_context_creation_info *info);
1303 LWS_EXTERN void
1304 lws_plat_drop_app_privileges(struct lws_context_creation_info *info);
1305 LWS_EXTERN unsigned long long
1306 time_in_microseconds(void);
1307 LWS_EXTERN const char *
1308 lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt);
1309
1310 #ifdef __cplusplus
1311 };
1312 #endif