Skip to content

Commit 6a933ef

Browse files
committed
fix #1002 ::Flush() wait for empty send buffer
1 parent 58937dd commit 6a933ef

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

libraries/ESP8266WiFi/src/WiFiClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ size_t WiFiClient::peekBytes(uint8_t *buffer, size_t length) {
259259
void WiFiClient::flush()
260260
{
261261
if (_client)
262-
_client->flush();
262+
_client->arduinoFlush();
263263
}
264264

265265
void WiFiClient::stop()

libraries/ESP8266WiFi/src/WiFiUdp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ int WiFiUDP::peek()
243243

244244
void WiFiUDP::flush()
245245
{
246-
if (_ctx)
247-
_ctx->flush();
246+
endPacket();
248247
}
249248

250249
IPAddress WiFiUDP::remoteIP()

libraries/ESP8266WiFi/src/include/ClientContext.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,17 @@ class ClientContext
290290
_rx_buf_offset = 0;
291291
}
292292

293+
void arduinoFlush()
294+
{
295+
#if 1
296+
// this is useless since _write_from_source() always exits with _datasource==NULL
297+
while (state() == ESTABLISHED && _datasource && _datasource->available()) {
298+
_write_some();
299+
delay(1); // esp_ schedule+yield
300+
}
301+
#endif
302+
}
303+
293304
uint8_t state() const
294305
{
295306
if(!_pcb) {

libraries/Ethernet/src/EthernetUdp.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ size_t EthernetUDP::write(const uint8_t *buffer, size_t size)
118118
int EthernetUDP::parsePacket()
119119
{
120120
// discard any remaining bytes in the last packet
121-
flush();
121+
clear_incoming();
122122

123123
if (recvAvailable(_sock) > 0)
124124
{
@@ -204,7 +204,7 @@ int EthernetUDP::peek()
204204
return b;
205205
}
206206

207-
void EthernetUDP::flush()
207+
void EthernetUDP::clear_remaining()
208208
{
209209
// could this fail (loop endlessly) if _remaining > 0 and recv in read fails?
210210
// should only occur if recv fails after telling us the data is there, lets
@@ -216,3 +216,8 @@ void EthernetUDP::flush()
216216
}
217217
}
218218

219+
void EthernetUDP::flush()
220+
{
221+
endPacket();
222+
}
223+

libraries/Ethernet/src/EthernetUdp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class EthernetUDP : public UDP {
4949
uint16_t _remotePort; // remote port for the incoming packet whilst it's being processed
5050
uint16_t _offset; // offset into the packet being sent
5151
uint16_t _remaining; // remaining bytes of incoming packet yet to be processed
52+
53+
protected:
54+
void clear_remaining();
5255

5356
public:
5457
EthernetUDP(); // Constructor

0 commit comments

Comments
 (0)