File tree 1 file changed +13
-18
lines changed
libraries/ESP8266WiFi/src
1 file changed +13
-18
lines changed Original file line number Diff line number Diff line change @@ -186,24 +186,19 @@ size_t WiFiClient::write_P(PGM_P buf, size_t size)
186
186
187
187
char chunkUnit[WIFICLIENT_MAX_PACKET_SIZE + 1 ];
188
188
chunkUnit[WIFICLIENT_MAX_PACKET_SIZE] = ' \0 ' ;
189
- while (buf != NULL )
190
- {
191
- size_t chunkUnitLen;
192
- PGM_P chunkNext;
193
- chunkNext = (PGM_P)memcpy_P ((void *)chunkUnit, (PGM_VOID_P)buf, WIFICLIENT_MAX_PACKET_SIZE);
194
- if (chunkNext == NULL )
195
- {
196
- // no terminator, more data available
197
- buf += WIFICLIENT_MAX_PACKET_SIZE;
198
- chunkUnitLen = WIFICLIENT_MAX_PACKET_SIZE;
199
- }
200
- else
201
- {
202
- // reached terminator
203
- chunkUnitLen = chunkNext - buf;
204
- buf = NULL ;
205
- }
206
- if (size < WIFICLIENT_MAX_PACKET_SIZE) chunkUnitLen = size;
189
+ size_t remaining_size = size;
190
+
191
+ while (buf != NULL && remaining_size > 0 ) {
192
+ size_t chunkUnitLen = WIFICLIENT_MAX_PACKET_SIZE;
193
+
194
+ if (remaining_size < WIFICLIENT_MAX_PACKET_SIZE) chunkUnitLen = remaining_size;
195
+ // due to the memcpy signature, lots of casts are needed
196
+ memcpy_P ((void *)chunkUnit, (PGM_VOID_P)buf, chunkUnitLen);
197
+
198
+ buf += chunkUnitLen;
199
+ remaining_size -= chunkUnitLen;
200
+
201
+ // write is so overloaded, had to use the cast to get it pick the right one
207
202
_client->write ((const char *)chunkUnit, chunkUnitLen);
208
203
}
209
204
return size;
You can’t perform that action at this time.
0 commit comments