Skip to content

Commit 07bdf28

Browse files
committed
added Michael's AsyncTCP fixes for testing
1 parent fd49f03 commit 07bdf28

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

lib/AsyncTCP/library.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=AsyncTCP
2+
version=1.1.1
3+
author=Me-No-Dev
4+
maintainer=Me-No-Dev
5+
sentence=Async TCP Library for ESP32
6+
paragraph=Async TCP Library for ESP32
7+
category=Other
8+
url=https://github.com/me-no-dev/AsyncTCP
9+
architectures=*

lib/AsyncTCP/src/AsyncTCP.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ typedef struct {
8585
} lwip_event_packet_t;
8686

8787
static QueueHandle_t _async_queue;
88-
static TaskHandle_t _async_service_task_handle = NULL;
88+
static TaskHandle_t _async_service_task_handle = NULL;
8989

9090

9191
SemaphoreHandle_t _slots_lock;
@@ -226,7 +226,8 @@ static bool _start_async_task() {
226226
return false;
227227
}
228228
if (!_async_service_task_handle) {
229-
xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);
229+
// xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);
230+
xTaskCreate(_async_service_task, "async_tcp", 8192, NULL, CONFIG_ASYNC_TCP_TASK_PRIORITY, &_async_service_task_handle);
230231
if (!_async_service_task_handle) {
231232
return false;
232233
}
@@ -1040,9 +1041,12 @@ size_t AsyncClient::write(const char * data) {
10401041

10411042
size_t AsyncClient::write(const char * data, size_t size, uint8_t apiflags) {
10421043
size_t will_send = add(data, size, apiflags);
1043-
if (!will_send || !send()) {
1044+
if (!will_send) {
10441045
return 0;
10451046
}
1047+
while (connected() && !send()) {
1048+
taskYIELD();
1049+
}
10461050
return will_send;
10471051
}
10481052

@@ -1080,6 +1084,18 @@ bool AsyncClient::getNoDelay() {
10801084
return tcp_nagle_disabled(_pcb);
10811085
}
10821086

1087+
void AsyncClient::setKeepAlive(uint32_t ms, uint8_t cnt) {
1088+
if (ms != 0) {
1089+
_pcb->so_options |= SOF_KEEPALIVE; //Turn on TCP Keepalive for the given pcb
1090+
// Set the time between keepalive messages in milli-seconds
1091+
_pcb->keep_idle = ms;
1092+
_pcb->keep_intvl = ms;
1093+
_pcb->keep_cnt = cnt; //The number of unanswered probes required to force closure of the socket
1094+
} else {
1095+
_pcb->so_options &= ~SOF_KEEPALIVE; //Turn off TCP Keepalive for the given pcb
1096+
}
1097+
}
1098+
10831099
uint16_t AsyncClient::getMss() {
10841100
if (!_pcb) {
10851101
return 0;

lib/AsyncTCP/src/AsyncTCP.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "sdkconfig.h"
2828
#include <functional>
2929
extern "C" {
30+
#include "freertos/FreeRTOS.h"
3031
#include "freertos/semphr.h"
3132
#include "lwip/pbuf.h"
3233
#include "lwip/ip_addr.h"
@@ -36,7 +37,11 @@ extern "C" {
3637
//If core is not defined, then we are running in Arduino or PIO
3738
#ifndef CONFIG_ASYNC_TCP_RUNNING_CORE
3839
#define CONFIG_ASYNC_TCP_RUNNING_CORE -1 //any available core
39-
#define CONFIG_ASYNC_TCP_USE_WDT 1 //if enabled, adds between 33us and 200us per event
40+
#define CONFIG_ASYNC_TCP_USE_WDT 0 //if enabled, adds between 33us and 200us per event
41+
#endif
42+
43+
#ifndef CONFIG_ASYNC_TCP_TASK_PRIORITY
44+
#define CONFIG_ASYNC_TCP_TASK_PRIORITY 15
4045
#endif
4146

4247
class AsyncClient;
@@ -103,6 +108,8 @@ class AsyncClient {
103108
void setNoDelay(bool nodelay);
104109
bool getNoDelay();
105110

111+
void setKeepAlive(uint32_t ms, uint8_t cnt);
112+
106113
uint32_t getRemoteAddress();
107114
ip6_addr_t getRemoteAddress6();
108115
uint16_t getRemotePort();

0 commit comments

Comments
 (0)