Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Commit

Permalink
Fix _recv method
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Oct 13, 2024
1 parent b11bfff commit d198248
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
8 changes: 4 additions & 4 deletions examples/Client/Client.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// 16 slots on esp32 (CONFIG_LWIP_MAX_ACTIVE_TCP)
#define MAX_CLIENTS CONFIG_LWIP_MAX_ACTIVE_TCP
// #define MAX_CLIENTS 3
// #define MAX_CLIENTS 1

size_t permits = MAX_CLIENTS;

Expand Down Expand Up @@ -52,8 +52,7 @@ void makeRequest() {
});

client->onData([](void* arg, AsyncClient* client, void* data, size_t len) {
Serial.printf("** data received by client: %" PRIu16 "\n", client->localPort());
// Serial.write((uint8_t*)data, len);
Serial.printf("** data received by client: %" PRIu16 ": len=%u\n", client->localPort(), len);
});

client->write("GET / HTTP/1.1\r\nHost: " HOST "\r\nUser-Agent: ESP\r\nConnection: close\r\n\r\n");
Expand Down Expand Up @@ -84,5 +83,6 @@ void setup() {
}

void loop() {
delay(500);
delay(1000);
Serial.printf("** free heap: %" PRIu32 "\n", ESP.getFreeHeap());
}
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build_flags =
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096
-D CONFIG_ARDUHAL_LOG_COLORS
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
upload_protocol = esptool
monitor_speed = 115200
monitor_filters = esp32_exception_decoder, log2file
Expand Down
27 changes: 6 additions & 21 deletions src/AsyncTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,8 @@ static esp_err_t _tcp_write(tcp_pcb * pcb, int8_t closed_slot, const char* data,
static err_t _tcp_recved_api(struct tcpip_api_call_data *api_call_msg){
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
msg->err = ERR_CONN;
// original code:
// causes the issue: assert failed: tcp_update_rcv_ann_wnd IDF/components/lwip/lwip/src/core/tcp.c:951 (new_rcv_ann_wnd <= 0xffff)
// if(msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot]) {

// attempted fix 1, which was rolled back since non reproductible after middleware support in ESPAsyncWebServer but works in some cases:
// - https://github.com/tbnobody/OpenDTU/discussions/2326
// - https://github.com/mathieucarbou/AsyncTCP/pull/24
if(msg->closed_slot != INVALID_CLOSED_SLOT && !_closed_slots[msg->closed_slot]) {

// attempted fix 2,
// - OpenDTU testing: https://github.com/tbnobody/OpenDTU/discussions/2326
// - Original fix https://github.com/me-no-dev/AsyncTCP/pull/173/files#diff-5312944d5b5f39741f3827dd678a8e828e2624ceab236264c025ef2bdf400d6aR422-R428
// Seems to have side effects: https://github.com/me-no-dev/ESPAsyncWebServer/issues/1437
if(msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot]) {
// if(msg->closed_slot != INVALID_CLOSED_SLOT && !_closed_slots[msg->closed_slot]) {
// if(msg->closed_slot != INVALID_CLOSED_SLOT) {
msg->err = 0;
tcp_recved(msg->pcb, msg->received);
Expand Down Expand Up @@ -996,19 +985,13 @@ int8_t AsyncClient::_sent(tcp_pcb* pcb, uint16_t len) {
}

int8_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) {
if(!_pcb || pcb != _pcb){
log_d("0x%08x != 0x%08x", (uint32_t)pcb, (uint32_t)_pcb);
return ERR_OK;
}
size_t total = 0;
while((pb != NULL) && (ERR_OK == err)) {
while(pb != NULL) {
_rx_last_packet = millis();
//we should not ack before we assimilate the data
_ack_pcb = true;
pbuf *b = pb;
pb = b->next;
b->next = NULL;
total += b->len;
if(_pb_cb){
_pb_cb(_pb_cb_arg, this, b);
} else {
Expand All @@ -1017,11 +1000,13 @@ int8_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) {
}
if(!_ack_pcb) {
_rx_ack_len += b->len;
} else if(_pcb) {
_tcp_recved(_pcb, _closed_slot, b->len);
}
}
pbuf_free(b);
}
return _tcp_recved(pcb, _closed_slot, total);
return ERR_OK;
}

int8_t AsyncClient::_poll(tcp_pcb* pcb){
Expand Down

0 comments on commit d198248

Please sign in to comment.