diff --git a/lib/AsyncTCP/library.properties b/lib/AsyncTCP/library.properties new file mode 100644 index 000000000..0a4068a46 --- /dev/null +++ b/lib/AsyncTCP/library.properties @@ -0,0 +1,9 @@ +name=AsyncTCP +version=1.1.1 +author=Me-No-Dev +maintainer=Me-No-Dev +sentence=Async TCP Library for ESP32 +paragraph=Async TCP Library for ESP32 +category=Other +url=https://github.com/me-no-dev/AsyncTCP +architectures=* \ No newline at end of file diff --git a/lib/AsyncTCP/src/AsyncTCP.cpp b/lib/AsyncTCP/src/AsyncTCP.cpp index 4b5c25acb..00bab60ad 100644 --- a/lib/AsyncTCP/src/AsyncTCP.cpp +++ b/lib/AsyncTCP/src/AsyncTCP.cpp @@ -85,7 +85,7 @@ typedef struct { } lwip_event_packet_t; static QueueHandle_t _async_queue; -static TaskHandle_t _async_service_task_handle = NULL; +static TaskHandle_t _async_service_task_handle = NULL; SemaphoreHandle_t _slots_lock; @@ -226,7 +226,8 @@ static bool _start_async_task() { return false; } if (!_async_service_task_handle) { - xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE); + // xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE); + xTaskCreate(_async_service_task, "async_tcp", 8192, NULL, CONFIG_ASYNC_TCP_TASK_PRIORITY, &_async_service_task_handle); if (!_async_service_task_handle) { return false; } @@ -1040,9 +1041,12 @@ size_t AsyncClient::write(const char * data) { size_t AsyncClient::write(const char * data, size_t size, uint8_t apiflags) { size_t will_send = add(data, size, apiflags); - if (!will_send || !send()) { + if (!will_send) { return 0; } + while (connected() && !send()) { + taskYIELD(); + } return will_send; } @@ -1080,6 +1084,18 @@ bool AsyncClient::getNoDelay() { return tcp_nagle_disabled(_pcb); } +void AsyncClient::setKeepAlive(uint32_t ms, uint8_t cnt) { + if (ms != 0) { + _pcb->so_options |= SOF_KEEPALIVE; //Turn on TCP Keepalive for the given pcb + // Set the time between keepalive messages in milli-seconds + _pcb->keep_idle = ms; + _pcb->keep_intvl = ms; + _pcb->keep_cnt = cnt; //The number of unanswered probes required to force closure of the socket + } else { + _pcb->so_options &= ~SOF_KEEPALIVE; //Turn off TCP Keepalive for the given pcb + } +} + uint16_t AsyncClient::getMss() { if (!_pcb) { return 0; diff --git a/lib/AsyncTCP/src/AsyncTCP.h b/lib/AsyncTCP/src/AsyncTCP.h index 855f2f7f1..6f03a1650 100644 --- a/lib/AsyncTCP/src/AsyncTCP.h +++ b/lib/AsyncTCP/src/AsyncTCP.h @@ -27,6 +27,7 @@ #include "sdkconfig.h" #include extern "C" { +#include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "lwip/pbuf.h" #include "lwip/ip_addr.h" @@ -36,7 +37,11 @@ extern "C" { //If core is not defined, then we are running in Arduino or PIO #ifndef CONFIG_ASYNC_TCP_RUNNING_CORE #define CONFIG_ASYNC_TCP_RUNNING_CORE -1 //any available core -#define CONFIG_ASYNC_TCP_USE_WDT 1 //if enabled, adds between 33us and 200us per event +#define CONFIG_ASYNC_TCP_USE_WDT 0 //if enabled, adds between 33us and 200us per event +#endif + +#ifndef CONFIG_ASYNC_TCP_TASK_PRIORITY +#define CONFIG_ASYNC_TCP_TASK_PRIORITY 15 #endif class AsyncClient; @@ -103,6 +108,8 @@ class AsyncClient { void setNoDelay(bool nodelay); bool getNoDelay(); + void setKeepAlive(uint32_t ms, uint8_t cnt); + uint32_t getRemoteAddress(); ip6_addr_t getRemoteAddress6(); uint16_t getRemotePort();