Skip to content

Commit b08d282

Browse files
d-a-vdevyte
authored andcommitted
fix connection reset by peer case (#4626)
* fix connection reset by peer case where pcb is set to null in ClientContext::_error but not reported to WiFiClient * ClientContext: rename functions *_sent to *_acked (:sent to :ack in debug) * use nullptr instead of 0
1 parent 4305275 commit b08d282

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Diff for: libraries/ESP8266WiFi/src/WiFiClient.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ void WiFiClient::stop()
280280

281281
uint8_t WiFiClient::connected()
282282
{
283-
if (!_client)
283+
if (!_client || _client->state() == CLOSED)
284284
return 0;
285285

286286
return _client->state() == ESTABLISHED || available();

Diff for: libraries/ESP8266WiFi/src/include/ClientContext.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ClientContext
4040
tcp_setprio(pcb, TCP_PRIO_MIN);
4141
tcp_arg(pcb, this);
4242
tcp_recv(pcb, &_s_recv);
43-
tcp_sent(pcb, &_s_sent);
43+
tcp_sent(pcb, &_s_acked);
4444
tcp_err(pcb, &_s_error);
4545
tcp_poll(pcb, &_s_poll, 1);
4646

@@ -58,7 +58,7 @@ class ClientContext
5858
tcp_err(_pcb, NULL);
5959
tcp_poll(_pcb, NULL, 0);
6060
tcp_abort(_pcb);
61-
_pcb = 0;
61+
_pcb = nullptr;
6262
}
6363
return ERR_ABRT;
6464
}
@@ -79,7 +79,7 @@ class ClientContext
7979
tcp_abort(_pcb);
8080
err = ERR_ABRT;
8181
}
82-
_pcb = 0;
82+
_pcb = nullptr;
8383
}
8484
return err;
8585
}
@@ -471,11 +471,11 @@ class ClientContext
471471
}
472472
}
473473

474-
err_t _sent(tcp_pcb* pcb, uint16_t len)
474+
err_t _acked(tcp_pcb* pcb, uint16_t len)
475475
{
476476
(void) pcb;
477477
(void) len;
478-
DEBUGV(":sent %d\r\n", len);
478+
DEBUGV(":ack %d\r\n", len);
479479
_write_some_from_cb();
480480
return ERR_OK;
481481
}
@@ -536,7 +536,7 @@ class ClientContext
536536
tcp_sent(_pcb, NULL);
537537
tcp_recv(_pcb, NULL);
538538
tcp_err(_pcb, NULL);
539-
_pcb = NULL;
539+
_pcb = nullptr;
540540
_notify_error();
541541
}
542542

@@ -571,9 +571,9 @@ class ClientContext
571571
return reinterpret_cast<ClientContext*>(arg)->_poll(tpcb);
572572
}
573573

574-
static err_t _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len)
574+
static err_t _s_acked(void *arg, struct tcp_pcb *tpcb, uint16_t len)
575575
{
576-
return reinterpret_cast<ClientContext*>(arg)->_sent(tpcb, len);
576+
return reinterpret_cast<ClientContext*>(arg)->_acked(tpcb, len);
577577
}
578578

579579
static err_t _s_connected(void* arg, struct tcp_pcb *pcb, err_t err)

0 commit comments

Comments
 (0)