Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libraries/ESP8266WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ bool WiFiClient::stop(unsigned int maxWaitMs)
return ret;
}

void WiFiClient::stop_abort() //Compare this to ::stop
{
if (!_client)
return;

_client->unref_abort();
_client = 0;
}

uint8_t WiFiClient::connected()
{
if (!_client || _client->state() == CLOSED)
Expand Down
1 change: 1 addition & 0 deletions libraries/ESP8266WiFi/src/WiFiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class WiFiClient : public Client, public SList<WiFiClient> {
bool stop(unsigned int maxWaitMs);
virtual uint8_t connected() override;
virtual operator bool() override;
virtual void stop_abort();

IPAddress remoteIP();
uint16_t remotePort();
Expand Down
52 changes: 29 additions & 23 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,25 @@ class ClientContext
return _pcb;
}

err_t abort()
err_t close(bool force_close = true, bool force_abort = false)
{
err_t err = force_close? ERR_OK: ERR_ABRT;
if(_pcb) {
DEBUGV(":abort\r\n");
DEBUGV(":close:%d abort:%d\r\n", force_close, force_abort);
tcp_arg(_pcb, NULL);
tcp_sent(_pcb, NULL);
tcp_recv(_pcb, NULL);
tcp_err(_pcb, NULL);
tcp_poll(_pcb, NULL, 0);
tcp_abort(_pcb);
_pcb = nullptr;
}
return ERR_ABRT;
}

err_t close()
{
err_t err = ERR_OK;
if(_pcb) {
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 (force_close)
err = tcp_close(_pcb);
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;
}
Expand All @@ -92,6 +83,16 @@ class ClientContext
return err;
}

err_t abort()
{
return close(false, true);
}

err_t close_abort()
{
return close(true, true);
}

~ClientContext()
{
}
Expand All @@ -113,19 +114,24 @@ class ClientContext
DEBUGV(":ref %d\r\n", _refcnt);
}

void unref()
void unref(bool force_abort = false)
{
DEBUGV(":ur %d\r\n", _refcnt);
if(--_refcnt == 0) {
discard_received();
close();
close(true, force_abort);
if(_discard_cb) {
_discard_cb(_discard_cb_arg, this);
}
DEBUGV(":del\r\n");
delete this;
}
}

void unref_abort()
{
unref(true);
}

int connect(ip_addr_t* addr, uint16_t port)
{
Expand Down