Skip to content
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

fix WiFiClient::write(from flash or iram) #7951

Merged
merged 2 commits into from
Apr 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions libraries/ESP8266WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern "C"
#include "lwip/netif.h"
#include <include/ClientContext.h>
#include "c_types.h"
#include <StreamDev.h>

uint16_t WiFiClient::_localPort = 0;

Expand Down Expand Up @@ -212,7 +213,8 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
return 0;
}
_client->setTimeout(_timeout);
return _client->write(buf, size);
StreamConstPtr ptr(buf, size);
return _client->write(ptr);
}

size_t WiFiClient::write(Stream& stream, size_t unused)
Expand All @@ -227,8 +229,12 @@ size_t WiFiClient::write(Stream& stream)
{
return 0;
}
_client->setTimeout(_timeout);
return _client->write(stream);
if (stream.hasPeekBufferAPI())
{
_client->setTimeout(_timeout);
return _client->write(stream);
}
return stream.sendAvailable(this);
}

size_t WiFiClient::write_P(PGM_P buf, size_t size)
Expand All @@ -238,7 +244,8 @@ size_t WiFiClient::write_P(PGM_P buf, size_t size)
return 0;
}
_client->setTimeout(_timeout);
return _client->write_P(buf, size);
StreamConstPtr nopeek(buf, size);
return nopeek.sendAll(this);
}

int WiFiClient::available()
Expand Down
21 changes: 2 additions & 19 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern "C" void esp_schedule();

#include <assert.h>
#include <StreamDev.h>
#include <esp_priv.h>

bool getDefaultPrivateGlobalSyncValue ();

Expand Down Expand Up @@ -372,32 +373,15 @@ class ClientContext
return _pcb->state;
}

size_t write(const uint8_t* data, size_t size)
{
if (!_pcb) {
return 0;
}
StreamConstPtr ptr(data, size);
return _write_from_source(&ptr);
}

size_t write(Stream& stream)
{
if (!_pcb) {
return 0;
}
assert(stream.hasPeekBufferAPI());
return _write_from_source(&stream);
}

size_t write_P(PGM_P buf, size_t size)
{
if (!_pcb) {
return 0;
}
StreamConstPtr ptr(buf, size);
return _write_from_source(&ptr);
}

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)
{
if (idle_sec && intv_sec && count) {
Expand Down Expand Up @@ -504,7 +488,6 @@ class ClientContext
// Give scheduled functions a chance to run (e.g. Ethernet uses recurrent)
delay(1);
// will resume on timeout or when _write_some_from_cb or _notify_error fires

}
_send_waiting = false;
} while(true);
Expand Down