File tree 4 files changed +30
-4
lines changed
libraries/ESP8266WiFi/src
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
179
179
180
180
virtual int read () override
181
181
{
182
- return _peekPointer < _size ? _buffer[_peekPointer++] : -1 ;
182
+ // valid with dram, iram and flash
183
+ return _peekPointer < _size ? pgm_read_byte (&_buffer[_peekPointer++]) : -1 ;
183
184
}
184
185
185
186
virtual int peek () override
186
187
{
187
- return _peekPointer < _size ? _buffer[_peekPointer] : -1 ;
188
+ // valid with dram, iram and flash
189
+ return _peekPointer < _size ? pgm_read_byte (&_buffer[_peekPointer]) : -1 ;
188
190
}
189
191
190
192
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
441
441
442
442
Two additional classes are provided.
443
443
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).
445
445
446
446
With this class, a ``Stream:: `` can be made from ``const char* ``,
447
447
``F("some words in flash") `` or ``PROGMEM `` strings. This class makes
@@ -451,7 +451,7 @@ Stream extensions
451
451
452
452
.. code :: cpp
453
453
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
455
455
server.sendAll(css);
456
456
457
457
- ``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() {
263
263
return false ;
264
264
}
265
265
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
+
266
287
size_t WiFiClientSecureCtx::_write (const uint8_t *buf, size_t size, bool pmem) {
267
288
size_t sent_bytes = 0 ;
268
289
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ class WiFiClientSecureCtx : public WiFiClient {
58
58
void flush () override { (void )flush (0 ); }
59
59
void stop () override { (void )stop (0 ); }
60
60
61
+ int availableForWrite () override ;
62
+
61
63
// Allow sessions to be saved/restored automatically to a memory area
62
64
void setSession (Session *session) { _session = session; }
63
65
@@ -249,6 +251,7 @@ class WiFiClientSecure : public WiFiClient {
249
251
size_t write (Stream& stream) /* Note this is not virtual */ { return _ctx->write (stream); }
250
252
int read (uint8_t *buf, size_t size) override { return _ctx->read (buf, size); }
251
253
int available () override { return _ctx->available (); }
254
+ int availableForWrite () override { return _ctx->availableForWrite (); }
252
255
int read () override { return _ctx->read (); }
253
256
int peek () override { return _ctx->peek (); }
254
257
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