WifiClient::write refactoring (second attempt) #2177
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Another attempt to do the same thing as in #1570.
WiFiClient::write
used to block for every call until data was acknowledged by remote side. This also meant that for a series ofWiFiClient::write
orWiFiClient::print
calls, each call would actually invoke tcp_output to send data and wait for acknowledgement, making the whole process really slow. Also with that designWiFiClient::setNoDelay
didn't have any effect — because Nagle algorithm was never used in the first place.With this change,
WiFiClient::write
will return as soon as all supplied data has been passed to the TCP stack. In practice that means that as much as 2 * 1460 bytes can be sent beforeWiFiClient::write
will block. This change also changesWiFiClient::write
behaviour for large blocks of data. Previously it would only write as much as TCP stack was willing to take (usually 2 * 1460 bytes) and not more. Now write method actually tries to send all data, i.e. if all data can not be sent at once, it will wait for more buffer space to be available and then send the rest. I'm also considering addingWiFiClient::setNonBlocking(bool)
method to disable blocking altogether.This change also removes all split-into-chunks-and-write code from ESP8266WebServer library because this is now handled by WiFiClient.