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
ClientContext: put things together
  • Loading branch information
d-a-v committed Sep 18, 2018
commit 5cf60b6e9a8ed439ec9aa8162907ec0e501332b2
18 changes: 8 additions & 10 deletions libraries/ESP8266WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ bool WiFiClient::getNoDelay() const {

void WiFiClient::setSync(bool sync)
{
if(!_client)
if (!_client)
return;
_client->setSync(sync);
}

bool WiFiClient::getSync() const
{
if(!_client)
if (!_client)
return false;
return _client->getSync();
}
Expand Down Expand Up @@ -285,21 +285,19 @@ size_t WiFiClient::peekBytes(uint8_t *buffer, size_t length) {
return _client->peekBytes((char *)buffer, count);
}

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

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

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

uint8_t WiFiClient::connected()
Expand Down
6 changes: 2 additions & 4 deletions libraries/ESP8266WiFi/src/WiFiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ class WiFiClient : public Client, public SList<WiFiClient> {
size_t peekBytes(char *buffer, size_t length) {
return peekBytes((uint8_t *) buffer, length);
}
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 void flush();
virtual void stop();
virtual uint8_t connected();
virtual operator bool();

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

bool wait_until_sent(int max_wait_ms = WIFICLIENT_MAX_FLUSH_WAIT_MS)
void wai 10000 t_until_sent()
{
if (!_pcb)
return true;

tcp_output(_pcb);

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

max_wait_ms++;
if (!_pcb)
return;

tcp_output(_pcb);

int max_wait_ms = WIFICLIENT_MAX_FLUSH_WAIT_MS + 1;

// 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
delay(1); // yields

#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 Expand Up @@ -461,13 +459,15 @@ class ClientContext
if (!next_chunk_size)
break;
const uint8_t* buf = _datasource->get_buffer(next_chunk_size);
// TCP_WRITE_FLAG_MORE to remove PUSH flag from packet (lwIP's doc), implicitely disables nagle (see lwIP's tcp_out.c)
// use TCP_WRITE_FLAG_MORE to remove PUSH flag from packet (lwIP's doc),
// because PUSH implicitely disables nagle (see lwIP's tcp_out.c)
// Notes:
// PUSH is for peer, telling to give to user app as soon as received
// PUSH may be set when sender has finished sending a meaningful data block
// Nagle is for delaying local stack, to send less and bigger packets
uint8_t flags = TCP_WRITE_FLAG_MORE; // do not tcp-PuSH (XXX always?)
// PUSH is for peer, telling to give data to user app as soon as received
// PUSH "may be set" when sender has finished sending a meaningful data block
// Nagle is for delaying local data, to send less/bigger packets
uint8_t flags = TCP_WRITE_FLAG_MORE; // do not tcp-PuSH
if (!_sync)
// user data will not stay in place when data are sent but not acknowledged
flags |= TCP_WRITE_FLAG_COPY;
err_t err = tcp_write(_pcb, buf, next_chunk_size, flags);
DEBUGV(":wrc %d %d %d\r\n", next_chunk_size, will_send, (int)err);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will_send undefined, too

Expand All @@ -484,8 +484,8 @@ class ClientContext

if (has_written && (_sync || tcp_nagle_disabled(_pcb)))
{
// handle nagle manually because of TCP_WRITE_FLAG_MORE
// lwIP's tcp_output: "Find out what we can send and send it"
// handle no-Nagle manually because of TCP_WRITE_FLAG_MORE
// lwIP's tcp_output doc: "Find out what we can send and send it"
tcp_output(_pcb);
}

Expand All @@ -494,13 +494,10 @@ class ClientContext

void _write_some_from_cb()
{
// lwIP needs feeding
_write_some();

if (_send_waiting == 1) {
_send_waiting--;
esp_schedule();
}
esp_schedule();
}

err_t _acked(tcp_pcb* pcb, uint16_t len)
Expand Down
0