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 LWS_PLAT_FREERTOS
25 */
26
27#if !defined(LWS_ESP_PLATFORM)
28#define SOMAXCONN 3
29#endif
30
31#if defined(LWS_AMAZON_RTOS)
32 int
33 open(const char *path, int oflag, ...);
34#else
35 #include <fcntl.h>
36#endif
37
38 #include <strings.h>
39 #include <unistd.h>
40 #include <sys/stat.h>
41 #include <sys/types.h>
42 #include <sys/time.h>
43 #include <netdb.h>
44
45 #ifndef __cplusplus
46  #include <errno.h>
47 #endif
48 #include <signal.h>
49#if defined(LWS_AMAZON_RTOS)
50const char *
51gai_strerror(int);
52#else
53 #include <sys/socket.h>
54#endif
55
56#if defined(LWS_AMAZON_RTOS)
57 #include "FreeRTOS.h"
58#if defined(LWS_WITH_SYS_ASYNC_DNS)
59 #include "FreeRTOS_IP.h"
60#endif
61 #include "timers.h"
62#if defined(LWS_ESP_PLATFORM)
63 #include <esp_attr.h>
64#endif
65 #include <semphr.h>
66#else
67 #include "freertos/timers.h"
68#if defined(LWS_ESP_PLATFORM)
69 #include <esp_attr.h>
70#endif
71 #include <esp_system.h>
72 #include <esp_task_wdt.h>
73#endif
74
75#if defined(LWS_WITH_ESP32)
76#include "lwip/apps/sntp.h"
77#include <errno.h>
78#endif
79
80typedef SemaphoreHandle_t lws_mutex_t;
81#define lws_mutex_init(x)	x = xSemaphoreCreateMutex()
82#define lws_mutex_destroy(x)	vSemaphoreDelete(x)
83#define lws_mutex_lock(x)	(!xSemaphoreTake(x, portMAX_DELAY)) /*0 = OK */
84#define lws_mutex_unlock(x)	xSemaphoreGive(x)
85
86#include <lwip/sockets.h>
87
88 #if defined(LWS_BUILTIN_GETIFADDRS)
89  #include "./misc/getifaddrs.h"
90 #endif
91
92 #define LWS_ERRNO errno
93 #define LWS_EAGAIN EAGAIN
94 #define LWS_EALREADY EALREADY
95 #define LWS_EINPROGRESS EINPROGRESS
96 #define LWS_EINTR EINTR
97 #define LWS_EISCONN EISCONN
98 #define LWS_ENOTCONN ENOTCONN
99 #define LWS_EWOULDBLOCK EWOULDBLOCK
100 #define LWS_EADDRINUSE EADDRINUSE
101 #define LWS_ECONNABORTED ECONNABORTED
102
103 #define lws_set_blocking_send(wsi)
104
105 #ifndef LWS_NO_FORK
106  #ifdef LWS_HAVE_SYS_PRCTL_H
107   #include <sys/prctl.h>
108  #endif
109 #endif
110
111#if !defined(MSG_NOSIGNAL)
112#define MSG_NOSIGNAL 0
113#endif
114
115#define compatible_close(x) close(x)
116#define lws_plat_socket_offset() LWIP_SOCKET_OFFSET
117#define wsi_from_fd(A,B)  A->lws_lookup[B - lws_plat_socket_offset()]
118
119struct lws_context;
120struct lws;
121
122int
123insert_wsi(const struct lws_context *context, struct lws *wsi);
124
125#define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0
126
127#define LWS_PLAT_TIMER_TYPE		TimerHandle_t
128#define LWS_PLAT_TIMER_CB(name, var)	void name(TimerHandle_t var)
129#define LWS_PLAT_TIMER_CB_GET_OPAQUE(x) pvTimerGetTimerID(x)
130#define LWS_PLAT_TIMER_CREATE(name, interval, repeat, opaque, cb) \
131	xTimerCreate(name, pdMS_TO_TICKS(interval) ? pdMS_TO_TICKS(interval) : 1, \
132			repeat ? pdTRUE : 0, opaque, cb)
133#define LWS_PLAT_TIMER_DELETE(ptr)	xTimerDelete(ptr, 0)
134#define LWS_PLAT_TIMER_START(ptr)	xTimerStart(ptr, 0)
135#define LWS_PLAT_TIMER_STOP(ptr)	xTimerStop(ptr, 0)
136
137
138