Skip to content

Commit ca5aff0

Browse files
committed
Merge branch 'fix-flush' of https://github.com/cmaglie/Arduino
2 parents 96d4168 + b7173ed commit ca5aff0

File tree

5 files changed

+13
-20
lines changed

5 files changed

+13
-20
lines changed

build/shared/revisions.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ ARDUINO 1.6.7
22

33
[libraries]
44
* SPI: Added SPI.transfer16(...) function to SAM core.
5+
* Ethernet, WiFi, SoftwareSerial: Fixed flush() behaviour:
6+
the flush function is no more dropping the receive buffer, as per
7+
1.0 API specification. Thanks @drmpf
58

69
[core]
710
* Fixed wrong timings for HardwareSerial::flush() in SAM core. Thanks @borisff

hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,7 @@ size_t SoftwareSerial::write(uint8_t b)
469469

470470
void SoftwareSerial::flush()
471471
{
472-
if (!isListening())
473-
return;
474-
475-
uint8_t oldSREG = SREG;
476-
cli();
477-
_receive_buffer_head = _receive_buffer_tail = 0;
478-
SREG = oldSREG;
472+
// There is no tx buffering, simply return
479473
}
480474

481475
int SoftwareSerial::peek()

libraries/Ethernet/src/EthernetUdp.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ 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+
while (_remaining) {
122+
// could this fail (loop endlessly) if _remaining > 0 and recv in read fails?
123+
// should only occur if recv fails after telling us the data is there, lets
124+
// hope the w5100 always behaves :)
125+
read();
126+
}
122127

123128
if (recvAvailable(_sock) > 0)
124129
{
@@ -206,14 +211,7 @@ int EthernetUDP::peek()
206211

207212
void EthernetUDP::flush()
208213
{
209-
// could this fail (loop endlessly) if _remaining > 0 and recv in read fails?
210-
// should only occur if recv fails after telling us the data is there, lets
211-
// hope the w5100 always behaves :)
212-
213-
while (_remaining)
214-
{
215-
read();
216-
}
214+
// TODO: we should wait for TX buffer to be emptied
217215
}
218216

219217
/* Start EthernetUDP socket, listening at local port PORT */

libraries/WiFi/src/WiFiClient.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ int WiFiClient::peek() {
140140
}
141141

142142
void WiFiClient::flush() {
143-
while (available())
144-
read();
143+
// TODO: a real check to ensure transmission has been completed
145144
}
146145

147146
void WiFiClient::stop() {

libraries/WiFi/src/WiFiUdp.cpp

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

156156
void WiFiUDP::flush()
157157
{
158-
while (available())
159-
read();
158+
// TODO: a real check to ensure transmission has been completed
160159
}
161160

162161
IPAddress WiFiUDP::remoteIP()

0 commit comments

Comments
 (0)