Skip to content

Commit

Permalink
fix connection reset by peer case (#4626)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
d-a-v authored and devyte committed Apr 12, 2018
1 parent 4305275 commit b08d282
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void WiFiClient::stop()

uint8_t WiFiClient::connected()
{
if (!_client)
if (!_client || _client->state() == CLOSED)
return 0;

return _client->state() == ESTABLISHED || available();
Expand Down
16 changes: 8 additions & 8 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ClientContext
tcp_setprio(pcb, TCP_PRIO_MIN);
tcp_arg(pcb, this);
tcp_recv(pcb, &_s_recv);
tcp_sent(pcb, &_s_sent);
tcp_sent(pcb, &_s_acked);
tcp_err(pcb, &_s_error);
tcp_poll(pcb, &_s_poll, 1);

Expand All @@ -58,7 +58,7 @@ class ClientContext
tcp_err(_pcb, NULL);
tcp_poll(_pcb, NULL, 0);
tcp_abort(_pcb);
_pcb = 0;
_pcb = nullptr;
}
return ERR_ABRT;
}
Expand All @@ -79,7 +79,7 @@ class ClientContext
tcp_abort(_pcb);
err = ERR_ABRT;
}
_pcb = 0;
_pcb = nullptr;
}
return err;
}
Expand Down Expand Up @@ -471,11 +471,11 @@ class ClientContext
}
}

err_t _sent(tcp_pcb* pcb, uint16_t len)
err_t _acked(tcp_pcb* pcb, uint16_t len)
{
(void) pcb;
(void) len;
DEBUGV(":sent %d\r\n", len);
DEBUGV(":ack %d\r\n", len);
_write_some_from_cb();
return ERR_OK;
}
Expand Down Expand Up @@ -536,7 +536,7 @@ class ClientContext
tcp_sent(_pcb, NULL);
tcp_recv(_pcb, NULL);
tcp_err(_pcb, NULL);
_pcb = NULL;
_pcb = nullptr;
_notify_error();
}

Expand Down Expand Up @@ -571,9 +571,9 @@ class ClientContext
return reinterpret_cast<ClientContext*>(arg)->_poll(tpcb);
}

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

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

0 comments on commit b08d282

Please sign in to comment.