@@ -448,8 +448,22 @@ static int8_t _tcp_sent(void *arg, struct tcp_pcb *pcb, uint16_t len) {
448
448
return ERR_OK;
449
449
}
450
450
451
- static void _tcp_error (void *arg, int8_t err) {
451
+ void AsyncClient:: _tcp_error (void *arg, int8_t err) {
452
452
// ets_printf("+E: 0x%08x\n", arg);
453
+ AsyncClient *client = reinterpret_cast <AsyncClient *>(arg);
454
+ if (client && client->_pcb ) {
455
+ tcp_arg (client->_pcb , NULL );
456
+ if (client->_pcb ->state == LISTEN) {
457
+ tcp_sent (client->_pcb , NULL );
458
+ tcp_recv (client->_pcb , NULL );
459
+ tcp_err (client->_pcb , NULL );
460
+ tcp_poll (client->_pcb , NULL , 0 );
461
+ }
462
+ client->_pcb = nullptr ;
463
+ client->_free_closed_slot ();
464
+ }
465
+
466
+ // enqueue event to be processed in the async task for the user callback
453
467
lwip_tcp_event_packet_t *e = (lwip_tcp_event_packet_t *)malloc (sizeof (lwip_tcp_event_packet_t ));
454
468
if (!e) {
455
469
log_e (" Failed to allocate event packet" );
@@ -459,7 +473,7 @@ static void _tcp_error(void *arg, int8_t err) {
459
473
e->arg = arg;
460
474
e->error .err = err;
461
475
if (!_send_async_event (&e)) {
462
- free ((void *)(e));
476
+ :: free ((void *)(e));
463
477
}
464
478
}
465
479
@@ -1046,19 +1060,6 @@ int8_t AsyncClient::_connected(tcp_pcb *pcb, int8_t err) {
1046
1060
}
1047
1061
1048
1062
void AsyncClient::_error (int8_t err) {
1049
- if (_pcb) {
1050
- TCP_MUTEX_LOCK ();
1051
- tcp_arg (_pcb, NULL );
1052
- if (_pcb->state == LISTEN) {
1053
- tcp_sent (_pcb, NULL );
1054
- tcp_recv (_pcb, NULL );
1055
- tcp_err (_pcb, NULL );
1056
- tcp_poll (_pcb, NULL , 0 );
1057
- }
1058
- TCP_MUTEX_UNLOCK ();
1059
- _free_closed_slot ();
1060
- _pcb = NULL ;
1061
- }
1062
1063
if (_error_cb) {
1063
1064
_error_cb (_error_cb_arg, this , err);
1064
1065
}
0 commit comments