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) 50 const char * 51 gai_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 #include <esp_attr.h> 63 #include <semphr.h> 64 #else 65 #include "freertos/timers.h" 66 #include <esp_attr.h> 67 #include <esp_system.h> 68 #include <esp_task_wdt.h> 69 #endif 70 71 #if defined(LWS_WITH_ESP32) 72 #include "lwip/apps/sntp.h" 73 #include <errno.h> 74 #endif 75 76 typedef SemaphoreHandle_t lws_mutex_t; 77 #define lws_mutex_init(x) x = xSemaphoreCreateMutex() 78 #define lws_mutex_destroy(x) vSemaphoreDelete(x) 79 #define lws_mutex_lock(x) (!xSemaphoreTake(x, portMAX_DELAY)) /*0 = OK */ 80 #define lws_mutex_unlock(x) xSemaphoreGive(x) 81 82 #include <lwip/sockets.h> 83 84 #if defined(LWS_BUILTIN_GETIFADDRS) 85 #include "./misc/getifaddrs.h" 86 #endif 87 88 #define LWS_ERRNO errno 89 #define LWS_EAGAIN EAGAIN 90 #define LWS_EALREADY EALREADY 91 #define LWS_EINPROGRESS EINPROGRESS 92 #define LWS_EINTR EINTR 93 #define LWS_EISCONN EISCONN 94 #define LWS_ENOTCONN ENOTCONN 95 #define LWS_EWOULDBLOCK EWOULDBLOCK 96 #define LWS_EADDRINUSE EADDRINUSE 97 #define LWS_ECONNABORTED ECONNABORTED 98 99 #define lws_set_blocking_send(wsi) 100 101 #ifndef LWS_NO_FORK 102 #ifdef LWS_HAVE_SYS_PRCTL_H 103 #include <sys/prctl.h> 104 #endif 105 #endif 106 107 #if !defined(MSG_NOSIGNAL) 108 #define MSG_NOSIGNAL 0 109 #endif 110 111 #define compatible_close(x) close(x) 112 #define lws_plat_socket_offset() LWIP_SOCKET_OFFSET 113 #define wsi_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] 114 115 struct lws_context; 116 struct lws; 117 118 int 119 insert_wsi(const struct lws_context *context, struct lws *wsi); 120 121 #define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0 122 123 #define LWS_PLAT_TIMER_TYPE TimerHandle_t 124 #define LWS_PLAT_TIMER_CB(name, var) void name(TimerHandle_t var) 125 #define LWS_PLAT_TIMER_CB_GET_OPAQUE(x) pvTimerGetTimerID(x) 126 #define LWS_PLAT_TIMER_CREATE(name, interval, repeat, opaque, cb) \ 127 xTimerCreate(name, pdMS_TO_TICKS(interval) ? pdMS_TO_TICKS(interval) : 1, \ 128 repeat ? pdTRUE : 0, opaque, cb) 129 #define LWS_PLAT_TIMER_DELETE(ptr) xTimerDelete(ptr, 0) 130 #define LWS_PLAT_TIMER_START(ptr) xTimerStart(ptr, 0) 131 #define LWS_PLAT_TIMER_STOP(ptr) xTimerStop(ptr, 0) 132 133 134