File tree 2 files changed +26
-8
lines changed
2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -1616,21 +1616,37 @@ void AsyncServer::end() {
1616
1616
1617
1617
// runs on LwIP thread
1618
1618
int8_t AsyncServer::_accept (tcp_pcb *pcb, int8_t err) {
1619
- // ets_printf("+A: 0x%08x\n", pcb);
1619
+ if (!pcb) {
1620
+ log_e (" _accept failed: pcb is NULL" );
1621
+ return ERR_ABRT;
1622
+ }
1620
1623
if (_connect_cb) {
1621
1624
AsyncClient *c = new (std::nothrow) AsyncClient (pcb);
1622
- if (c) {
1625
+ if (c && c-> pcb () ) {
1623
1626
c->setNoDelay (_noDelay);
1624
- const int8_t err = _tcp_accept (this , c);
1625
- if (err != ERR_OK) {
1626
- tcp_abort (pcb);
1627
- delete c;
1627
+ if (_tcp_accept (this , c) == ERR_OK) {
1628
+ return ERR_OK; // success
1628
1629
}
1629
- return err;
1630
+ // Couldn't allocate accept event
1631
+ // 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
1632
+ c->_pcb = nullptr ;
1633
+ tcp_abort (pcb);
1634
+ log_e (" _accept failed: couldn't accept client" );
1635
+ return ERR_ABRT;
1630
1636
}
1637
+ if (c) {
1638
+ // Couldn't complete setup
1639
+ // pcb has already been aborted
1640
+ delete c;
1641
+ pcb = nullptr ;
1642
+ log_e (" _accept failed: couldn't complete setup" );
1643
+ return ERR_ABRT;
1644
+ }
1645
+ log_e (" _accept failed: couldn't allocate client" );
1646
+ } else {
1647
+ log_e (" _accept failed: no onConnect callback" );
1631
1648
}
1632
1649
tcp_abort (pcb);
1633
- log_d (" _accept failed" );
1634
1650
return ERR_OK;
1635
1651
}
1636
1652
Original file line number Diff line number Diff line change @@ -246,6 +246,8 @@ class AsyncClient {
246
246
}
247
247
248
248
protected:
249
+ friend class AsyncServer ;
250
+
249
251
bool _connect (ip_addr_t addr, uint16_t port);
250
252
251
253
tcp_pcb *_pcb;
You can’t perform that action at this time.
0 commit comments