@@ -128,11 +128,11 @@ static inline bool _init_async_event_queue() {
128
128
return true ;
129
129
}
130
130
131
- static inline bool _send_async_event (lwip_tcp_event_packet_t **e, TickType_t wait = portMAX_DELAY ) {
131
+ static inline bool _send_async_event (lwip_tcp_event_packet_t **e, TickType_t wait = 0 ) {
132
132
return _async_queue && xQueueSend (_async_queue, e, wait ) == pdPASS;
133
133
}
134
134
135
- static inline bool _prepend_async_event (lwip_tcp_event_packet_t **e, TickType_t wait = portMAX_DELAY ) {
135
+ static inline bool _prepend_async_event (lwip_tcp_event_packet_t **e, TickType_t wait = 0 ) {
136
136
return _async_queue && xQueueSendToFront (_async_queue, e, wait ) == pdPASS;
137
137
}
138
138
@@ -376,6 +376,7 @@ static int8_t _tcp_connected(void *arg, tcp_pcb *pcb, int8_t err) {
376
376
if (!_prepend_async_event (&e)) {
377
377
free ((void *)(e));
378
378
log_e (" Failed to queue event: LWIP_TCP_CONNECTED" );
379
+ tcp_abort (pcb);
379
380
return ERR_TIMEOUT;
380
381
}
381
382
return ERR_OK;
@@ -402,6 +403,7 @@ static int8_t _tcp_poll(void *arg, struct tcp_pcb *pcb) {
402
403
if (!_send_async_event (&e, 0 )) {
403
404
free ((void *)(e));
404
405
log_e (" Failed to queue event: LWIP_TCP_POLL" );
406
+ tcp_abort (pcb);
405
407
return ERR_TIMEOUT;
406
408
}
407
409
return ERR_OK;
@@ -431,6 +433,7 @@ static int8_t _tcp_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, int8_t
431
433
if (!_send_async_event (&e)) {
432
434
free ((void *)(e));
433
435
log_e (" Failed to queue event: LWIP_TCP_RECV or LWIP_TCP_FIN" );
436
+ tcp_abort (pcb);
434
437
return ERR_TIMEOUT;
435
438
}
436
439
return ERR_OK;
@@ -450,6 +453,7 @@ static int8_t _tcp_sent(void *arg, struct tcp_pcb *pcb, uint16_t len) {
450
453
if (!_send_async_event (&e)) {
451
454
free ((void *)(e));
452
455
log_e (" Failed to queue event: LWIP_TCP_SENT" );
456
+ tcp_abort (pcb);
453
457
return ERR_TIMEOUT;
454
458
}
455
459
return ERR_OK;
@@ -505,6 +509,7 @@ static int8_t _tcp_accept(void *arg, AsyncClient *client) {
505
509
if (!_prepend_async_event (&e)) {
506
510
free ((void *)(e));
507
511
log_e (" Failed to queue event: LWIP_TCP_ACCEPT" );
512
+ client->abort ();
508
513
return ERR_TIMEOUT;
509
514
}
510
515
return ERR_OK;
@@ -1639,28 +1644,32 @@ int8_t AsyncServer::_accept(tcp_pcb *pcb, int8_t err) {
1639
1644
return ERR_ABRT;
1640
1645
}
1641
1646
if (_connect_cb) {
1642
- AsyncClient *c = new (std::nothrow) AsyncClient (pcb);
1643
- if (c && c->pcb ()) {
1644
- c->setNoDelay (_noDelay);
1645
- if (_tcp_accept (this , c) == ERR_OK) {
1646
- return ERR_OK; // success
1647
+ if (uxQueueMessagesWaiting (_async_queue) < CONFIG_ASYNC_TCP_QUEUE_SIZE * 90 / 100 ) {
1648
+ AsyncClient *c = new (std::nothrow) AsyncClient (pcb);
1649
+ if (c && c->pcb ()) {
1650
+ c->setNoDelay (_noDelay);
1651
+ if (_tcp_accept (this , c) == ERR_OK) {
1652
+ return ERR_OK; // success
1653
+ }
1654
+ // Couldn't allocate accept event
1655
+ // 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
1656
+ c->_pcb = nullptr ;
1657
+ tcp_abort (pcb);
1658
+ log_e (" _accept failed: couldn't accept client" );
1659
+ return ERR_ABRT;
1647
1660
}
1648
- // Couldn't allocate accept event
1649
- // 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
1650
- c->_pcb = nullptr ;
1651
- tcp_abort (pcb);
1652
- log_e (" _accept failed: couldn't accept client" );
1653
- return ERR_ABRT;
1654
- }
1655
- if (c) {
1656
- // Couldn't complete setup
1657
- // pcb has already been aborted
1658
- delete c;
1659
- pcb = nullptr ;
1660
- log_e (" _accept failed: couldn't complete setup" );
1661
- return ERR_ABRT;
1661
+ if (c) {
1662
+ // Couldn't complete setup
1663
+ // pcb has already been aborted
1664
+ delete c;
1665
+ pcb = nullptr ;
1666
+ log_e (" _accept failed: couldn't complete setup" );
1667
+ return ERR_ABRT;
1668
+ }
1669
+ log_e (" _accept failed: couldn't allocate client" );
1670
+ } else {
1671
+ log_e (" _accept failed: queue full" );
1662
1672
}
1663
- log_e (" _accept failed: couldn't allocate client" );
1664
1673
} else {
1665
1674
log_e (" _accept failed: no onConnect callback" );
1666
1675
}
0 commit comments