Skip to content

Fix flush() behaviour on a bunch of classes/libraries #4133

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

Merged
merged 3 commits into from
Nov 18, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,7 @@ size_t SoftwareSerial::write(uint8_t b)

void SoftwareSerial::flush()
{
if (!isListening())
return;

uint8_t oldSREG = SREG;
cli();
_receive_buffer_head = _receive_buffer_tail = 0;
SREG = oldSREG;
// There is no tx buffering, simply return
}

int SoftwareSerial::peek()
Expand Down
16 changes: 7 additions & 9 deletions libraries/Ethernet/src/EthernetUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ size_t EthernetUDP::write(const uint8_t *buffer, size_t size)
int EthernetUDP::parsePacket()
{
// discard any remaining bytes in the last packet
flush();
while (_remaining) {
// could this fail (loop endlessly) if _remaining > 0 and recv in read fails?
// should only occur if recv fails after telling us the data is there, lets
// hope the w5100 always behaves :)
read();
}

if (recvAvailable(_sock) > 0)
{
Expand Down Expand Up @@ -206,14 +211,7 @@ int EthernetUDP::peek()

void EthernetUDP::flush()
{
// could this fail (loop endlessly) if _remaining > 0 and recv in read fails?
// should only occur if recv fails after telling us the data is there, lets
// hope the w5100 always behaves :)

while (_remaining)
{
read();
}
// TODO: we should wait for TX buffer to be emptied
}

/* Start EthernetUDP socket, listening at local port PORT */
Expand Down
3 changes: 1 addition & 2 deletions libraries/WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ int WiFiClient::peek() {
}

void WiFiClient::flush() {
while (available())
read();
// TODO: a real check to ensure transmission has been completed
}

void WiFiClient::stop() {
Expand Down
3 changes: 1 addition & 2 deletions libraries/WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ int WiFiUDP::peek()

void WiFiUDP::flush()
{
while (available())
read();
// TODO: a real check to ensure transmission has been completed
}

IPAddress WiFiUDP::remoteIP()
Expand Down