Skip to content

Commit fa24d77

Browse files
ficetoficeto
authored andcommitted
Add WiFiClient.write for Stream
reads directly from the stream and fragments the data to achieve maximum data throughput over WiFi
1 parent 2c1d353 commit fa24d77

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/WiFiClient.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,34 @@ size_t ICACHE_FLASH_ATTR WiFiClient::write(const uint8_t *buf, size_t size)
138138
return _client->write(reinterpret_cast<const char*>(buf), size);
139139
}
140140

141+
size_t ICACHE_FLASH_ATTR WiFiClient::write(Stream &src)
142+
{
143+
uint8_t obuf[1460];
144+
size_t doneLen = 0;
145+
size_t sentLen;
146+
int i;
147+
148+
while (src.available() > 1460)
149+
{
150+
for(i=0;i<1460;i++) obuf[i] = src.read();
151+
sentLen = write(obuf, 1460);
152+
doneLen = doneLen + sentLen;
153+
if(sentLen != 1460){
154+
DEBUGV("Sent: %u < 1460\r\n", sentLen);
155+
return doneLen;
156+
}
157+
}
158+
159+
uint16_t leftLen = src.available();
160+
for(i=0;i<leftLen;i++) obuf[i] = src.read();
161+
sentLen = write(obuf, leftLen);
162+
doneLen = doneLen + sentLen;
163+
if(sentLen != leftLen){
164+
DEBUGV("Sent: %u < %u\r\n", sentLen, leftLen);
165+
}
166+
return doneLen;
167+
}
168+
141169
extern "C" uint32_t esp_micros_at_task_start();
142170

143171
int ICACHE_FLASH_ATTR WiFiClient::available()

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/WiFiClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class WiFiClient : public Client {
5555

5656
IPAddress remoteIP();
5757
uint16_t remotePort();
58+
size_t write(Stream&);
5859

5960
friend class WiFiServer;
6061

0 commit comments

Comments
 (0)