@@ -223,6 +223,8 @@ AsyncClient::AsyncClient(tcp_pcb* pcb):
223223}
224224
225225AsyncClient::~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
355359void 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
364370void AsyncClient::stop () {
371+ ASYNC_TCP_DEBUG (" stop[%u]:%s\n " , getConnectionId ());
372+ _close_called = true ;
365373 close (false );
366374}
367375
368376bool 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
495505void 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
0 commit comments