Skip to content

Commit 225f58d

Browse files
author
Adam Suwała
committed
callbecks to error and disconnect handlers are ommited if one of closing methods was called
1 parent 1547686 commit 225f58d

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

22
.DS_Store
3+
.vscode

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ESPAsyncTCP
2-
[![Build Status](https://travis-ci.org/me-no-dev/ESPAsyncTCP.svg?branch=master)](https://travis-ci.org/me-no-dev/ESPAsyncTCP) ![](https://github.com/me-no-dev/ESPAsyncTCP/workflows/ESP%20Async%20TCP%20CI/badge.svg)
2+
3+
### Fixes
4+
- callbecks to error and disconnect handlers are ommited if one of closing methods was called
35

46
### Async TCP Library for ESP8266 Arduino
57

src/ESPAsyncTCP.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ AsyncClient::AsyncClient(tcp_pcb* pcb):
223223
}
224224

225225
AsyncClient::~AsyncClient(){
226+
ASYNC_TCP_DEBUG("~AsyncClient[%u]:%s\n", getConnectionId(), ((NULL == _pcb) ? " NULL == pcb" : ""));
227+
_close_called = true;
226228
if(_pcb)
227229
_close();
228230

@@ -344,6 +346,8 @@ void AsyncClient::abort(){
344346
// of a 2nd call to tcp_abort().
345347
// 6) Callbacks to _recv() or _connected() with err set, will result in _pcb
346348
// set to NULL. Thus, preventing possible calls later to tcp_abort().
349+
ASYNC_TCP_DEBUG("~AsyncClient[%u]\n", getConnectionId());
350+
_close_called = true;
347351
if(_pcb) {
348352
tcp_abort(_pcb);
349353
_pcb = NULL;
@@ -353,6 +357,8 @@ void AsyncClient::abort(){
353357
}
354358

355359
void AsyncClient::close(bool now){
360+
ASYNC_TCP_DEBUG("close[%u](%d):%s\n", getConnectionId(), now, ((NULL == _pcb) ? " NULL == pcb" : ""));
361+
_close_called = true;
356362
if(_pcb)
357363
tcp_recved(_pcb, _rx_ack_len);
358364
if(now)
@@ -362,10 +368,14 @@ void AsyncClient::close(bool now){
362368
}
363369

364370
void AsyncClient::stop() {
371+
ASYNC_TCP_DEBUG("stop[%u]:%s\n", getConnectionId());
372+
_close_called = true;
365373
close(false);
366374
}
367375

368376
bool AsyncClient::free(){
377+
ASYNC_TCP_DEBUG("free[%u]:%s\n", getConnectionId());
378+
_close_called = true;
369379
if(!_pcb)
370380
return true;
371381
if(_pcb->state == 0 || _pcb->state > 4)
@@ -493,6 +503,7 @@ void AsyncClient::_connected(std::shared_ptr<ACErrorTracker>& errorTracker, void
493503
}
494504

495505
void AsyncClient::_close(){
506+
ASYNC_TCP_DEBUG("_close[%u]:%s\n", getConnectionId(), ((NULL == _pcb) ? " NULL == pcb" : ""));
496507
if(_pcb) {
497508
#if ASYNC_TCP_SSL_ENABLED
498509
if(_pcb_secure){
@@ -526,9 +537,9 @@ void AsyncClient::_error(err_t err) {
526537
// made to set to NULL other callbacks.
527538
_pcb = NULL;
528539
}
529-
if(_error_cb)
540+
if(_error_cb && !_close_called)
530541
_error_cb(_error_cb_arg, this, err);
531-
if(_discard_cb)
542+
if(_discard_cb && !_close_called)
532543
_discard_cb(_discard_cb_arg, this);
533544
}
534545

src/ESPAsyncTCP.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class AsyncClient {
134134
uint32_t _pcb_sent_at;
135135
bool _close_pcb;
136136
bool _ack_pcb;
137+
bool _close_called = false;
137138
uint32_t _tx_unacked_len;
138139
uint32_t _tx_acked_len;
139140
uint32_t _tx_unsent_len;

0 commit comments

Comments
 (0)