File tree Expand file tree Collapse file tree 4 files changed +30
-4
lines changed
libraries/ESP8266WiFi/src Expand file tree Collapse file tree 4 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -179,12 +179,14 @@ class StreamConstPtr: public StreamNull
179179
180180 virtual int read () override
181181 {
182- return _peekPointer < _size ? _buffer[_peekPointer++] : -1 ;
182+ // valid with dram, iram and flash
183+ return _peekPointer < _size ? pgm_read_byte (&_buffer[_peekPointer++]) : -1 ;
183184 }
184185
185186 virtual int peek () override
186187 {
187- return _peekPointer < _size ? _buffer[_peekPointer] : -1 ;
188+ // valid with dram, iram and flash
189+ return _peekPointer < _size ? pgm_read_byte (&_buffer[_peekPointer]) : -1 ;
188190 }
189191
190192 virtual size_t readBytes (char * buffer, size_t len) override
Original file line number Diff line number Diff line change @@ -441,7 +441,7 @@ Stream extensions
441441
442442 Two additional classes are provided.
443443
444- - ``StreamPtr :: `` is designed to hold a constant buffer (in ram or flash).
444+ - ``StreamConstPtr :: `` is designed to hold a constant buffer (in ram or flash).
445445
446446 With this class, a ``Stream:: `` can be made from ``const char* ``,
447447 ``F("some words in flash") `` or ``PROGMEM `` strings. This class makes
@@ -451,7 +451,7 @@ Stream extensions
451451
452452 .. code :: cpp
453453
454- StreamPtr css(F("my long css data")); // CSS data not copied to RAM
454+ StreamConstPtr css(F("my long css data")); // CSS data not copied to RAM
455455 server.sendAll(css);
456456
457457 - ``S2Stream:: `` is designed to make a ``Stream:: `` out of a ``String:: `` without copy.
Original file line number Diff line number Diff line change @@ -263,6 +263,27 @@ uint8_t WiFiClientSecureCtx::connected() {
263263 return false ;
264264}
265265
266+ int WiFiClientSecureCtx::availableForWrite () {
267+ // code taken from ::_write()
268+ if (!connected () || !_handshake_done) {
269+ return 0 ;
270+ }
271+ // Get BearSSL to a state where we can send
272+ if (_run_until (BR_SSL_SENDAPP) < 0 ) {
273+ return 0 ;
274+ }
275+ if (br_ssl_engine_current_state (_eng) & BR_SSL_SENDAPP) {
276+ size_t sendapp_len;
277+ (void )br_ssl_engine_sendapp_buf (_eng, &sendapp_len);
278+ // We want to call br_ssl_engine_sendapp_ack(0) but 0 is forbidden (bssl doc).
279+ // After checking br_ssl_engine_sendapp_buf() src code,
280+ // it seems that it is OK to not call ack when the buffer is left untouched.
281+ // forbidden: br_ssl_engine_sendapp_ack(_eng, 0);
282+ return (int )sendapp_len;
283+ }
284+ return 0 ;
285+ }
286+
266287size_t WiFiClientSecureCtx::_write (const uint8_t *buf, size_t size, bool pmem) {
267288 size_t sent_bytes = 0 ;
268289
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ class WiFiClientSecureCtx : public WiFiClient {
5858 void flush () override { (void )flush (0 ); }
5959 void stop () override { (void )stop (0 ); }
6060
61+ int availableForWrite () override ;
62+
6163 // Allow sessions to be saved/restored automatically to a memory area
6264 void setSession (Session *session) { _session = session; }
6365
@@ -249,6 +251,7 @@ class WiFiClientSecure : public WiFiClient {
249251 size_t write (Stream& stream) /* Note this is not virtual */ { return _ctx->write (stream); }
250252 int read (uint8_t *buf, size_t size) override { return _ctx->read (buf, size); }
251253 int available () override { return _ctx->available (); }
254+ int availableForWrite () override { return _ctx->availableForWrite (); }
252255 int read () override { return _ctx->read (); }
253256 int peek () override { return _ctx->peek (); }
254257 size_t peekBytes (uint8_t *buffer, size_t length) override { return _ctx->peekBytes (buffer, length); }
You can’t perform that action at this time.
0 commit comments