1d4afb5ceSopenharmony_ci /* 2d4afb5ceSopenharmony_ci * libwebsockets - small server side websockets and web server implementation 3d4afb5ceSopenharmony_ci * 4d4afb5ceSopenharmony_ci * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com> 5d4afb5ceSopenharmony_ci * 6d4afb5ceSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 7d4afb5ceSopenharmony_ci * of this software and associated documentation files (the "Software"), to 8d4afb5ceSopenharmony_ci * deal in the Software without restriction, including without limitation the 9d4afb5ceSopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10d4afb5ceSopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is 11d4afb5ceSopenharmony_ci * furnished to do so, subject to the following conditions: 12d4afb5ceSopenharmony_ci * 13d4afb5ceSopenharmony_ci * The above copyright notice and this permission notice shall be included in 14d4afb5ceSopenharmony_ci * all copies or substantial portions of the Software. 15d4afb5ceSopenharmony_ci * 16d4afb5ceSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17d4afb5ceSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18d4afb5ceSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19d4afb5ceSopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20d4afb5ceSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21d4afb5ceSopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22d4afb5ceSopenharmony_ci * IN THE SOFTWARE. 23d4afb5ceSopenharmony_ci * 24d4afb5ceSopenharmony_ci * Included from lib/private-lib-core.h if LWS_PLAT_FREERTOS 25d4afb5ceSopenharmony_ci */ 26d4afb5ceSopenharmony_ci 27d4afb5ceSopenharmony_ci#if !defined(LWS_ESP_PLATFORM) 28d4afb5ceSopenharmony_ci#define SOMAXCONN 3 29d4afb5ceSopenharmony_ci#endif 30d4afb5ceSopenharmony_ci 31d4afb5ceSopenharmony_ci#if defined(LWS_AMAZON_RTOS) 32d4afb5ceSopenharmony_ci int 33d4afb5ceSopenharmony_ci open(const char *path, int oflag, ...); 34d4afb5ceSopenharmony_ci#else 35d4afb5ceSopenharmony_ci #include <fcntl.h> 36d4afb5ceSopenharmony_ci#endif 37d4afb5ceSopenharmony_ci 38d4afb5ceSopenharmony_ci #include <strings.h> 39d4afb5ceSopenharmony_ci #include <unistd.h> 40d4afb5ceSopenharmony_ci #include <sys/stat.h> 41d4afb5ceSopenharmony_ci #include <sys/types.h> 42d4afb5ceSopenharmony_ci #include <sys/time.h> 43d4afb5ceSopenharmony_ci #include <netdb.h> 44d4afb5ceSopenharmony_ci 45d4afb5ceSopenharmony_ci #ifndef __cplusplus 46d4afb5ceSopenharmony_ci #include <errno.h> 47d4afb5ceSopenharmony_ci #endif 48d4afb5ceSopenharmony_ci #include <signal.h> 49d4afb5ceSopenharmony_ci#if defined(LWS_AMAZON_RTOS) 50d4afb5ceSopenharmony_ciconst char * 51d4afb5ceSopenharmony_cigai_strerror(int); 52d4afb5ceSopenharmony_ci#else 53d4afb5ceSopenharmony_ci #include <sys/socket.h> 54d4afb5ceSopenharmony_ci#endif 55d4afb5ceSopenharmony_ci 56d4afb5ceSopenharmony_ci#if defined(LWS_AMAZON_RTOS) 57d4afb5ceSopenharmony_ci #include "FreeRTOS.h" 58d4afb5ceSopenharmony_ci#if defined(LWS_WITH_SYS_ASYNC_DNS) 59d4afb5ceSopenharmony_ci #include "FreeRTOS_IP.h" 60d4afb5ceSopenharmony_ci#endif 61d4afb5ceSopenharmony_ci #include "timers.h" 62d4afb5ceSopenharmony_ci #include <esp_attr.h> 63d4afb5ceSopenharmony_ci#else 64d4afb5ceSopenharmony_ci #include "freertos/timers.h" 65d4afb5ceSopenharmony_ci #include <esp_attr.h> 66d4afb5ceSopenharmony_ci #include <esp_system.h> 67d4afb5ceSopenharmony_ci #include <esp_task_wdt.h> 68d4afb5ceSopenharmony_ci#endif 69d4afb5ceSopenharmony_ci 70d4afb5ceSopenharmony_ci#if defined(LWS_WITH_ESP32) 71d4afb5ceSopenharmony_ci#include "lwip/apps/sntp.h" 72d4afb5ceSopenharmony_ci#include <errno.h> 73d4afb5ceSopenharmony_ci#endif 74d4afb5ceSopenharmony_ci 75d4afb5ceSopenharmony_citypedef SemaphoreHandle_t lws_mutex_t; 76d4afb5ceSopenharmony_ci#define lws_mutex_init(x) x = xSemaphoreCreateMutex() 77d4afb5ceSopenharmony_ci#define lws_mutex_destroy(x) vSemaphoreDelete(x) 78d4afb5ceSopenharmony_ci#define lws_mutex_lock(x) xSemaphoreTake(x, portMAX_DELAY) 79d4afb5ceSopenharmony_ci#define lws_mutex_unlock(x) xSemaphoreGive(x) 80d4afb5ceSopenharmony_ci 81d4afb5ceSopenharmony_ci#include <lwip/sockets.h> 82d4afb5ceSopenharmony_ci 83d4afb5ceSopenharmony_ci #if defined(LWS_BUILTIN_GETIFADDRS) 84d4afb5ceSopenharmony_ci #include "./misc/getifaddrs.h" 85d4afb5ceSopenharmony_ci #endif 86d4afb5ceSopenharmony_ci 87d4afb5ceSopenharmony_ci #define LWS_ERRNO errno 88d4afb5ceSopenharmony_ci #define LWS_EAGAIN EAGAIN 89d4afb5ceSopenharmony_ci #define LWS_EALREADY EALREADY 90d4afb5ceSopenharmony_ci #define LWS_EINPROGRESS EINPROGRESS 91d4afb5ceSopenharmony_ci #define LWS_EINTR EINTR 92d4afb5ceSopenharmony_ci #define LWS_EISCONN EISCONN 93d4afb5ceSopenharmony_ci #define LWS_ENOTCONN ENOTCONN 94d4afb5ceSopenharmony_ci #define LWS_EWOULDBLOCK EWOULDBLOCK 95d4afb5ceSopenharmony_ci #define LWS_EADDRINUSE EADDRINUSE 96d4afb5ceSopenharmony_ci 97d4afb5ceSopenharmony_ci #define lws_set_blocking_send(wsi) 98d4afb5ceSopenharmony_ci 99d4afb5ceSopenharmony_ci #ifndef LWS_NO_FORK 100d4afb5ceSopenharmony_ci #ifdef LWS_HAVE_SYS_PRCTL_H 101d4afb5ceSopenharmony_ci #include <sys/prctl.h> 102d4afb5ceSopenharmony_ci #endif 103d4afb5ceSopenharmony_ci #endif 104d4afb5ceSopenharmony_ci 105d4afb5ceSopenharmony_ci#if !defined(MSG_NOSIGNAL) 106d4afb5ceSopenharmony_ci#define MSG_NOSIGNAL 0 107d4afb5ceSopenharmony_ci#endif 108d4afb5ceSopenharmony_ci 109d4afb5ceSopenharmony_ci#define compatible_close(x) close(x) 110d4afb5ceSopenharmony_ci#define lws_plat_socket_offset() LWIP_SOCKET_OFFSET 111d4afb5ceSopenharmony_ci#define wsi_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] 112d4afb5ceSopenharmony_ci 113d4afb5ceSopenharmony_cistruct lws_context; 114d4afb5ceSopenharmony_cistruct lws; 115d4afb5ceSopenharmony_ci 116d4afb5ceSopenharmony_ciint 117d4afb5ceSopenharmony_ciinsert_wsi(const struct lws_context *context, struct lws *wsi); 118d4afb5ceSopenharmony_ci 119d4afb5ceSopenharmony_ci#define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0 120d4afb5ceSopenharmony_ci 121d4afb5ceSopenharmony_ci#define LWS_PLAT_TIMER_TYPE TimerHandle_t 122d4afb5ceSopenharmony_ci#define LWS_PLAT_TIMER_CB(name, var) void name(TimerHandle_t var) 123d4afb5ceSopenharmony_ci#define LWS_PLAT_TIMER_CB_GET_OPAQUE(x) pvTimerGetTimerID(x) 124d4afb5ceSopenharmony_ci#define LWS_PLAT_TIMER_CREATE(name, interval, repeat, opaque, cb) \ 125d4afb5ceSopenharmony_ci xTimerCreate(name, pdMS_TO_TICKS(interval) ? pdMS_TO_TICKS(interval) : 1, \ 126d4afb5ceSopenharmony_ci repeat ? pdTRUE : 0, opaque, cb) 127d4afb5ceSopenharmony_ci#define LWS_PLAT_TIMER_DELETE(ptr) xTimerDelete(ptr, 0) 128d4afb5ceSopenharmony_ci#define LWS_PLAT_TIMER_START(ptr) xTimerStart(ptr, 0) 129d4afb5ceSopenharmony_ci#define LWS_PLAT_TIMER_STOP(ptr) xTimerStop(ptr, 0) 130d4afb5ceSopenharmony_ci 131d4afb5ceSopenharmony_ci 132