Skip to content
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

ClientContext (tcp) updates #5089

Merged
merged 39 commits into from
Sep 25, 2018
Merged

ClientContext (tcp) updates #5089

merged 39 commits into from
Sep 25, 2018

Conversation

d-a-v
Copy link
Collaborator

@d-a-v d-a-v commented Aug 28, 2018

  • make Nagle work properly (default is unchanged: disabled = NoDelay enabled)
  • add client.setSync(bool) (= "always flush" mode)
    slower when enabled but allocates less memory and data are always flushed
  • client.stop() implicitely calls .flush() (flush has a small timeout anyway)
  • add static WiFiClient::setDefaultSync(bool)/::setDefaultNoDelay(bool)
  • internal: remove PuSH flag from data packet

Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

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

I think you need to compile with full debugging options. I'm seeing build failures due to variables you've done away with still setting in DEBUGV lines.

if (_pcb->snd_queuelen >= TCP_SND_QUEUELEN) {
can_send = 0;
}
size_t will_send = (can_send < left) ? can_send : left;
DEBUGV(":wr %d %d %d\r\n", will_send, left, _written);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The debug lines fail to compile due to them trying to dump variables that were just removed (left)

// 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

@earlephilhower
Copy link
Collaborator

Functionally, when compiled w/o debugging, this patch doesn't seem to cause any problems with BearSSL or axTLS in simple testing (bssl_validatiaon, https_request).

d-a-v and others added 13 commits September 18, 2018 09:35
Simple refactor to make WiFiClientSecureAxTLS use an external header to
define its SSLContext, just as it does for several other classes.

Fixes esp8266#3648
As part of the "clear connection configuration for reused objects"
patch, a ::stop would reset the self-signed, trust anchors, etc.
WiFiClient, unfortunately, calls ::stop as part of the connection
process, so all of these settings were lost.

Now only clear the connection settings on ::stop if we've already
been connected.

Also update the github public key which changed yet again.

Fixes esp8266#5086
Copy link
Collaborator

@devyte devyte left a comment

Choose a reason for hiding this comment

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

Kudos on the constness!

libraries/ESP8266WiFi/src/WiFiClient.h Outdated Show resolved Hide resolved
@@ -35,7 +35,7 @@ class ClientContext
{
public:
ClientContext(tcp_pcb* pcb, discard_cb_t discard_cb, void* discard_cb_arg) :
_pcb(pcb), _rx_buf(0), _rx_buf_offset(0), _discard_cb(discard_cb), _discard_cb_arg(discard_cb_arg), _refcnt(0), _next(0)
_pcb(pcb), _rx_buf(0), _rx_buf_offset(0), _discard_cb(discard_cb), _discard_cb_arg(discard_cb_arg), _refcnt(0), _next(0), _sync(WiFiClient::getDefaultSync())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bad idea, because it needlessly creates a circular dependency: ClientContext depends on WiFiClient, and WiFiClient depends on ClientContext. I suggest either factoring the sync into its own .h/.cpp, or pushing its declaration/definition into ClientContext.h/.cpp for reuse by WiFiClient class.

@@ -42,6 +42,8 @@ extern "C"
#include "c_types.h"

uint16_t WiFiClient::_localPort = 0;
bool WiFiClient::_defaultNoDelay = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest a big fat comment here about what the four combinations of nodelay and sync do, because I can't for the life of me keep them straight in my head.

@earlephilhower
Copy link
Collaborator

@d-a-v, there's something weird in the tree and it's failing with the EthernetClient example builds. Very odd! Maybe it was using the ClientContext and something got broken?

Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

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

As far as the SSL side goes, looks fine to me. Minor niggle on some C operator early-terminator, but would not -1 the patch for it. Thanks for the heads-up!

{
if (_client)
_client->wait_until_sent();
return !_client || _client->wait_until_sent(maxWaitMs?: WIFICLIENT_MAX_FLUSH_WAIT_MS);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I get the shorthand, but using the early-termination feature to avoid an if-then could be confusing

}
WiFiClient::stop();
bool WiFiClientSecure::stop(unsigned int maxWaitMs) {
bool ret = WiFiClient::stop(maxWaitMs); // calls our virtual flush()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see ::stop calls ::flush so we're OK there. Why I did _client->abort() as well, I couldn't tell you. LGTM.

@earlephilhower
Copy link
Collaborator

The build problem is the changes to the flush and stop signature. Need to update the EthernetClient sources to have the new timeout parameter w/defaults...

@d-a-v
Copy link
Collaborator Author

d-a-v commented Sep 24, 2018

doc is visible there: client and server.

Added details for getters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants