8000 Added close_abort() function to WiFiClient by pfabri · Pull Request #2767 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Added close_abort() function to WiFiClient #2767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
merge close and close_abort
  • Loading branch information
d-a-v authored Jan 8, 2020
commit 98c64db36a737c2ca2381db47315438575c13ce5
37 changes: 12 additions & 25 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,47 +66,34 @@ class ClientContext
return ERR_ABRT;
}

err_t close()
err_t close(bool force_abort = false)
{
err_t err = ERR_OK;
if(_pcb) {
DEBUGV(":close\r\n");
if (force_abort)
DEBUGV(":closeabort\r\n");
else
DEBUGV(":close\r\n");
tcp_arg(_pcb, NULL);
tcp_sent(_pcb, NULL);
tcp_recv(_pcb, NULL);
tcp_err(_pcb, NULL);
tcp_poll(_pcb, NULL, 0);
err = tcp_close(_pcb);
if(err != ERR_OK) {
DEBUGV(":tc err %d\r\n", (int) err);
if(err != ERR_OK || force_abort) {
if (force_abort)
/* Without delay some clients fail to receive the response and
* report a 'cannot connect' error message */
delay(10);
else
DEBUGV(":tc err %d\r\n", (int) err);
tcp_abort(_pcb);
err = ERR_ABRT;
}
_pcb = nullptr;
}
return err;
}

err_t close_abort()
{
/* ERR_ABRT must be sent back on abortion as specified in the comments
* of tools/sdk/lwip/src/core/tcp.c at the footnote of tcp_abort() */
err_t err = ERR_ABRT;
if(_pcb) {
DEBUGV(":close\r\n");
tcp_arg(_pcb, NULL);
tcp_sent(_pcb, NULL);
tcp_recv(_pcb, NULL);
tcp_err(_pcb, NULL);
tcp_close(_pcb);
/* Without delay some clients fail to receive the response and
* report a 'cannot connect' error message */
delay(10);
tcp_abort(_pcb);
_pcb = 0;
}
return err;
}

~ClientContext()
{
Expand Down
0