private-lib-plat-freertos.h 3.7 KB

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