Skip to content

Commit 1c57b34

Browse files
authored
fix WiFiClient::write(from flash or iram) (#7951)
* fix WiFiClient::write(flash or iram) * fix emulation on host
1 parent 5ac64ff commit 1c57b34

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

libraries/ESP8266WiFi/src/WiFiClient.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extern "C"
4040
#include "lwip/netif.h"
4141
#include <include/ClientContext.h>
4242
#include "c_types.h"
43+
#include <StreamDev.h>
4344

4445
uint16_t WiFiClient::_localPort = 0;
4546

@@ -212,7 +213,8 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
212213
return 0;
213214
}
214215
_client->setTimeout(_timeout);
215-
return _client->write(buf, size);
216+
StreamConstPtr ptr(buf, size);
217+
return _client->write(ptr);
216218
}
217219

218220
size_t WiFiClient::write(Stream& stream, size_t unused)
@@ -227,8 +229,12 @@ size_t WiFiClient::write(Stream& stream)
227229
{
228230
return 0;
229231
}
230-
_client->setTimeout(_timeout);
231-
return _client->write(stream);
232+
if (stream.hasPeekBufferAPI())
233+
{
234+
_client->setTimeout(_timeout);
235+
return _client->write(stream);
236+
}
237+
return stream.sendAvailable(this);
232238
}
233239

234240
size_t WiFiClient::write_P(PGM_P buf, size_t size)
@@ -238,7 +244,8 @@ size_t WiFiClient::write_P(PGM_P buf, size_t size)
238244
return 0;
239245
}
240246
_client->setTimeout(_timeout);
241-
return _client->write_P(buf, size);
247+
StreamConstPtr nopeek(buf, size);
248+
return nopeek.sendAll(this);
242249
}
243250

244251
int WiFiClient::available()

libraries/ESP8266WiFi/src/include/ClientContext.h

+2-19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern "C" void esp_schedule();
3131

3232
#include <assert.h>
3333
#include <StreamDev.h>
34+
#include <esp_priv.h>
3435

3536
bool getDefaultPrivateGlobalSyncValue ();
3637

@@ -372,32 +373,15 @@ class ClientContext
372373
return _pcb->state;
373374
}
374375

375-
size_t write(const uint8_t* data, size_t size)
376-
{
377-
if (!_pcb) {
378-
return 0;
379-
}
380-
StreamConstPtr ptr(data, size);
381-
return _write_from_source(&ptr);
382-
}
383-
384376
size_t write(Stream& stream)
385377
{
386378
if (!_pcb) {
387379
return 0;
388380
}
381+
assert(stream.hasPeekBufferAPI());
389382
return _write_from_source(&stream);
390383
}
391384

392-
size_t write_P(PGM_P buf, size_t size)
393-
{
394-
if (!_pcb) {
395-
return 0;
396-
}
397-
StreamConstPtr ptr(buf, size);
398-
return _write_from_source(&ptr);
399-
}
400-
401385
void keepAlive (uint16_t idle_sec = TCP_DEFAULT_KEEPALIVE_IDLE_SEC, uint16_t intv_sec = TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC, uint8_t count = TCP_DEFAULT_KEEPALIVE_COUNT)
402386
{
403387
if (idle_sec && intv_sec && count) {
@@ -504,7 +488,6 @@ class ClientContext
504488
// Give scheduled functions a chance to run (e.g. Ethernet uses recurrent)
505489
delay(1);
506490
// will resume on timeout or when _write_some_from_cb or _notify_error fires
507-
508491
}
509492
_send_waiting = false;
510493
} while(true);

0 commit comments

Comments
 (0)