8000 ClientContext (tcp) updates by d-a-v · Pull Request #5089 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

ClientContext (tcp) updates #5089

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

Merged
merged 39 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6c64759
wip
d-a-v Aug 22, 2018
746ec81
cc wip
d-a-v Aug 22, 2018
53c9222
cc wip
d-a-v Aug 22, 2018
6de50d4
cc comments
d-a-v Aug 22, 2018
2dd152d
wip cc
d-a-v Aug 24, 2018
f87602a
+sync, get/set default nodelay, sync
d-a-v Aug 27, 2018
6be4b6f
default nodelay=1
d-a-v Aug 28, 2018
8f7fb1e
update flush()
d-a-v Aug 28, 2018
c0bea2b
fix return value
d-a-v Aug 28, 2018
d00ac35
ClientContext: put things together
d-a-v Aug 28, 2018
53931c5
wip
d-a-v Aug 22, 2018
81ec0f4
cc wip
d-a-v Aug 22, 2018
fbf1dd1
cc wip
d-a-v Aug 22, 2018
b4a918f
cc comments
d-a-v Aug 22, 2018
c14eeef
wip cc
d-a-v Aug 24, 2018
238610e
+sync, get/set default nodelay, sync
d-a-v Aug 27, 2018
d0036a1
default nodelay=1
d-a-v Aug 28, 2018
e4c187b
update flush()
d-a-v Aug 28, 2018
d31d6f2
fix return value
d-a-v Aug 28, 2018
5cf60b6
ClientContext: put things together
d-a-v Aug 28, 2018
a058506
Move SSLContext to its own header (#5121)
earlephilhower Sep 17, 2018
a7a5959
Fix connection options and update github pubkey (#5120)
earlephilhower Sep 17, 2018
d06cac2
ClientContext: fix debugging messages
d-a-v Sep 18, 2018
e8c659e
Merge branch 'master' into ClientContext
earlephilhower Sep 18, 2018
f271b2a
WiFiClient: move static members out of the class, add comments
d-a-v Sep 18, 2018
7f57694
Merge branch 'ClientContext' of github.com:d-a-v/Arduino into ClientC…
d-a-v Sep 18, 2018
888bdb8
remove circular dependency
d-a-v Sep 19, 2018
c59a91f
parameter and return value for Client::flush&stop, flush timeout rais…
d-a-v Sep 22, 2018
3c54c9e
Merge branch 'master' into ClientContext
d-a-v Sep 23, 2018
8414e17
tcp flush: restart timer on ack receive
d-a-v Sep 23, 2018
4d62879
OTA protocol needs setNoDelay(true)
d-a-v Sep 23, 2018
826b8b5
fix Ethernet with Client changes
d-a-v Sep 23, 2018
3fa6a97
1 line unredable -> 5 lines readable code
d-a-v Sep 23, 2018
72b59d9
Merge branch 'master' into ClientContext
d-a-v Sep 24, 2018
7752c98
doc
d-a-v Sep 24, 2018
c160d17
doc
d-a-v Sep 24, 2018
db8fe6c
doc
d-a-v Sep 24, 2018
8bb444d
doc
d-a-v Sep 24, 2018
33dee32
Update client-class.rst
devyte Sep 24, 2018
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
Prev Previous commit
Next Next commit
update flush()
  • Loading branch information
d-a-v committed Aug 28, 2018
commit 8f7fb1e1ec9646af17752a044173ee88f3852e4d
13 changes: 8 additions & 5 deletions libraries/ESP8266WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,21 @@ size_t WiFiClient::peekBytes(uint8_t *buffer, size_t length) {
return _client->peekBytes((char *)buffer, count);
}

void WiFiClient::flush()
bool WiFiClient::flush(int maxWaitMs)
{
if (_client)
_client->wait_until_sent();
return !_client || _client->wait_until_sent(maxWaitMs);
return true;
}

void WiFiClient::stop()
bool WiFiClient::stop(int maxWaitMs)
{
if (!_client)
return;
return true;

_client->close();
bool ok = _client->wait_until_sent(maxWaitMs);
ok &= _client->close() == ERR_OK;
return ok;
}

uint8_t WiFiClient::connected()
Expand Down
13 changes: 10 additions & 3 deletions libraries/ESP8266WiFi/src/WiFiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
#include "IPAddress.h"
#include "include/slist.h"

#define WIFICLIENT_MAX_PACKET_SIZE 1460
#ifndef TCP_MSS
#define TCP_MSS 1460 // lwip1.4
#endif

#define WIFICLIENT_MAX_PACKET_SIZE TCP_MSS
#define WIFICLIENT_MAX_FLUSH_WAIT_MS 100

#define TCP_DEFAULT_KEEPALIVE_IDLE_SEC 7200 // 2 hours
#define TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC 75 // 75 sec
Expand Down Expand Up @@ -67,8 +72,10 @@ class WiFiClient : public Client, public SList<WiFiClient> {
size_t peekBytes(char *buffer, size_t length) {
return peekBytes((uint8_t *) buffer, length);
}
virtual void flush();
virtual void stop();
bool flush(int maxWaitMs);
bool stop(int maxWaitMs);
virtual void flush() { flush(WIFICLIENT_MAX_FLUSH_WAIT_MS); }
virtual void stop() { stop(WIFICLIENT_MAX_FLUSH_WAIT_MS); }
virtual uint8_t connected();
virtual operator bool();

Expand Down
26 changes: 18 additions & 8 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,30 @@ class ClientContext
_rx_buf_offset = 0;
}

void wait_until_sent()
bool wait_until_sent(int max_wait_ms = WIFICLIENT_MAX_FLUSH_WAIT_MS)
{
// fix option 1 in
// https://github.com/esp8266/Arduino/pull/3967#pullrequestreview-83451496
// TODO: option 2
if (!_pcb)
return;
tcp_output(_pcb);

#define WAIT_TRIES_MS 10 // at most 10ms
// https://github.com/esp8266/Arduino/pull/3967#pullrequestreview-83451496
// option 1 done
// option 2 / _write_some() not necessary since _datasource is always nullptr here

int tries = 1+ WAIT_TRIES_MS;
max_wait_ms++;

while (state() == ESTABLISHED && tcp_sndbuf(_pcb) != TCP_SND_BUF && --tries) {
//_write_some();
// wait for peer's acks flushing lwIP's output buffer
while (state() == ESTABLISHED && tcp_sndbuf(_pcb) != TCP_SND_BUF && --max_wait_ms)
delay(1); // esp_ schedule+yield

#ifdef DEBUGV
if (max_wait_ms == 0) {
// wait until sent: timeout
DEBUGV(":wustmo\n");
}
#endif

return max_wait_ms > 0;
}

uint8_t state() const
Expand Down
0