@@ -126,11 +126,11 @@ static inline bool _init_async_event_queue() {
126
126
return true ;
127
127
}
128
128
129
- static inline bool _send_async_event (lwip_tcp_event_packet_t **e, TickType_t wait = portMAX_DELAY ) {
129
+ static inline bool _send_async_event (lwip_tcp_event_packet_t **e, TickType_t wait = 0 ) {
130
130
return _async_queue && xQueueSend (_async_queue, e, wait ) == pdPASS;
131
131
}
132
132
133
- static inline bool _prepend_async_event (lwip_tcp_event_packet_t **e, TickType_t wait = portMAX_DELAY ) {
133
+ static inline bool _prepend_async_event (lwip_tcp_event_packet_t **e, TickType_t wait = 0 ) {
134
134
return _async_queue && xQueueSendToFront (_async_queue, e, wait ) == pdPASS;
135
135
}
136
136
@@ -374,6 +374,7 @@ static int8_t _tcp_connected(void *arg, tcp_pcb *pcb, int8_t err) {
374
374
if (!_prepend_async_event (&e)) {
375
375
free ((void *)(e));
376
376
log_e (" Failed to queue event: LWIP_TCP_CONNECTED" );
377
+ tcp_abort (pcb);
377
378
return ERR_TIMEOUT;
378
379
}
379
380
return ERR_OK;
@@ -400,6 +401,7 @@ static int8_t _tcp_poll(void *arg, struct tcp_pcb *pcb) {
400
401
if (!_send_async_event (&e, 0 )) {
401
402
free ((void *)(e));
402
403
log_e (" Failed to queue event: LWIP_TCP_POLL" );
404
+ tcp_abort (pcb);
403
405
return ERR_TIMEOUT;
404
406
}
405
407
return ERR_OK;
@@ -429,6 +431,7 @@ static int8_t _tcp_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, int8_t
429
431
if (!_send_async_event (&e)) {
430
432
free ((void *)(e));
431
433
log_e (" Failed to queue event: LWIP_TCP_RECV or LWIP_TCP_FIN" );
434
+ tcp_abort (pcb);
432
435
return ERR_TIMEOUT;
433
436
}
434
437
return ERR_OK;
@@ -448,6 +451,7 @@ static int8_t _tcp_sent(void *arg, struct tcp_pcb *pcb, uint16_t len) {
448
451
if (!_send_async_event (&e)) {
449
452
free ((void *)(e));
450
453
log_e (" Failed to queue event: LWIP_TCP_SENT" );
454
+ tcp_abort (pcb);
451
455
return ERR_TIMEOUT;
452
456
}
453
457
return ERR_OK;
@@ -503,6 +507,7 @@ static int8_t _tcp_accept(void *arg, AsyncClient *client) {
503
507
if (!_prepend_async_event (&e)) {
504
508
free ((void *)(e));
505
509
log_e (" Failed to queue event: LWIP_TCP_ACCEPT" );
510
+ client->abort ();
506
511
return ERR_TIMEOUT;
507
512
}
508
513
return ERR_OK;
@@ -1637,28 +1642,32 @@ int8_t AsyncServer::_accept(tcp_pcb *pcb, int8_t err) {
1637
1642
return ERR_ABRT;
1638
1643
}
1639
1644
if (_connect_cb) {
1640
- AsyncClient *c = new (std::nothrow) AsyncClient (pcb);
1641
- if (c && c->pcb ()) {
1642
- c->setNoDelay (_noDelay);
1643
- if (_tcp_accept (this , c) == ERR_OK) {
1644
- return ERR_OK; // success
1645
+ if (uxQueueMessagesWaiting (_async_queue) < CONFIG_ASYNC_TCP_QUEUE_SIZE * 90 / 100 ) {
1646
+ AsyncClient *c = new (std::nothrow) AsyncClient (pcb);
1647
+ if (c && c->pcb ()) {
1648
+ c->setNoDelay (_noDelay);
1649
+ if (_tcp_accept (this , c) == ERR_OK) {
1650
+ return ERR_OK; // success
1651
+ }
1652
+ // Couldn't allocate accept event
1653
+ // We can't let the client object call in to close, as we're on the LWIP thread; it could deadlock trying to RPC to itself
1654
+ c->_pcb = nullptr ;
1655
+ tcp_abort (pcb);
1656
+ log_e (" _accept failed: couldn't accept client" );
1657
+ return ERR_ABRT;
1645
1658
}
1646
- // Couldn't allocate accept event
1647
- // We can't let the client object call in to close, as we're on the LWIP thread; it could deadlock trying to RPC to itself
1648
- c->_pcb = nullptr ;
1649
- tcp_abort (pcb);
1650
- log_e (" _accept failed: couldn't accept client" );
1651
- return ERR_ABRT;
1652
- }
1653
- if (c) {
1654
- // Couldn't complete setup
1655
- // pcb has already been aborted
1656
- delete c;
1657
- pcb = nullptr ;
1658
- log_e (" _accept failed: couldn't complete setup" );
1659
- return ERR_ABRT;
1659
+ if (c) {
1660
+ // Couldn't complete setup
1661
+ // pcb has already been aborted
1662
+ delete c;
1663
+ pcb = nullptr ;
1664
+ log_e (" _accept failed: couldn't complete setup" );
1665
+ return ERR_ABRT;
1666
+ }
1667
+ log_e (" _accept failed: couldn't allocate client" );
1668
+ } else {
1669
+ log_e (" _accept failed: queue full" );
1660
1670
}
1661
- log_e (" _accept failed: couldn't allocate client" );
1662
1671
} else {
1663
1672
log_e (" _accept failed: no onConnect callback" );
1664
1673
}
0 commit comments