-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Stream::send() #6979
Stream::send() #6979
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now. Appreciate the clearer naming!
At this point it was found that wpos is above rpos, i.e.: the ringbuffer has a single contiguous block, with possible free mem at the bottom and at the top. If at this point there is an interrupt that causes wpos to wrap, the returned value below will be wrong, i.e.: some large number because of negative result returned as size_t type. Then, in SendGenericPeekBuffer(), the to->write() call will crash.
Congrats, @d-a-v! |
Hello, I would like to confirm my founding. It seems that the updated ESP8266WebServer (and maybe ESP8266WiFi) relies on the non32xfer service because:
Then, because which mean that the buffer will be read using non PGM method. Also, there is another CTOR: It casts Then
So it seems that PSTR strings still need to be accessed using the I found that if I do not enable/include the non32xfer service then calls to web server It seems also the case for SSL web server (even with non32xfer enabled, my SSL web server failed to send anything to the browser despite it does not cause exception 3). I am still unsure why this behavior with SSL happened. I want to ask if this was by design (non32xfer must be enabled/included)? I need to inform you that until at least the new official Arduino package is released, I will not be able to produce a test sketch because like I said to @earlephilhower in my other discussion, I do not use the Arduino build system. Because I also follow updates from Arduino ESP8266 GIT and then modify the cores a bit to match my need and style, my application code will not compile using Arduino's original core. Therefore, I am also not sure if my comment about this is actually valid when using the original core and Arduino IDE. Thank you! |
@blue-wind-25 Can you cut-n-paste your observation into a new issue for tracking? A closed PR can easily get overlooked. Thx! |
edit:
fixes #6907 (datasource is replaced by stream) (comment)
edit:
References to "String is Stream" are removed:
An helper class
S2Stream myStringVarNowIsAStream(myStringVar)
has been added to make an already existingString
into aStream
, andStreamString
derives from it.edit:
+ device test combined with an example
+ documentation
edit:
WiFiEcho
server sketch example, with provided python echo client:(these results are environment-dependent and have been made under the same conditions)
Optional virtual peekBuffer API to allow direct access to data (internal Stream API, currently implemented by HardwareSerial and WiFiClient/Secure)
API addition is summarized here (user facing API)
Additional notes:
ClientContext
:DataSource
is removed and replaced byStream::
offering the same services: from Stream, from in-ram data, from in-flash data). That's also an additional reduction of allocation frequency.Cost:
BasicHttpClient.ino:
(less than 1KB in flash)with master:
w/
Stream::to
PR:Ref: plerup/espsoftwareserial#171 replaced by#7840Ref: bblanchon/ArduinoJson#1341OP: (fixed)
This pull request aims at simplifying transfers between sources (
Stream
,String
) and destinations (Print
,String
) in a single function in a single location.This kind of transfer is indeed reimplemented everytime it is needed making the esp8266 arduino core (or any code using
Stream
) hard to optimize or maintain. There are no general functionality difference between any of these transfers.The proposed implementation is in the form of "Stream::to*(Print)". This function relies on Arduino virtual Stream and Print API. The Arduino Stream API is historically limited so such transfers require the use of an intermediary buffer, implying two copies. This pull request also proposes an extension to the Stream API which allows to reduce the number of copies and avoid the use of such buffer. It is called in the following the "
peekBuffer
extension".The
peekBuffer
extension is not a breaking change. It is by default not available (ie disabled inStream::
) and can be enabled by any stream class extender (bool Stream::peekBufferAPI()
).This pull request enables the
Stream
'speekBuffer
API inWiFiClient::
,WiFiClientSecureBearSSL::
,HardwareSerial::
andStreamString::
. The latter is optionally merged withString::
and this can be seen as a breaking change in some particular cases where libraries like ArduinoJson has overloads forStream::
andString::
.At the time of writing,
Stream
'speekBuffer
API has yet to be implemented in the filesystem classes (SDFat
,LittleFS
,SPIFFS
).Implementing it in external libraries such as
EspSoftwareSerial
should not induce changes in binary size or API compatibility with other cores.Lots of places in the esp8266 arduino core would benefit from
Stream::to()
. This pull request proposes changes toESP8266HTTPClient
(it allowed to remove some big chunks of code including the interestingHTTPClient::writeToStreamDataBlock()
). This change is (partly) validated by the device testtest_sw_http_client
(http, https) that can also be run-tested on host.Some parts of
ESP8266WebServer
have been updated to useStream::to()
. Some examples too (Telnet2Serial, serial tests, ...) deserves the same changes.A new example called
WiFiEcho
has been added to demonstrate the simplicity of the API.About the functions
Stream::to*()
, they allow toStream
to aPrint
The timeout used is by default the stream's one and can be changed in arguments.
The
peekBuffer
API is used when available and avoids the use of an intermediary buffer with a twofold effect: speed and absence of any kind of stack/heap allocation.When
peekBuffer
is not available,Stream::to()
does the job using the legacy way.