From 934475b75bc2ef64c109ed857f3d302b20f28a56 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 11 Nov 2015 16:28:48 +0100 Subject: [PATCH 1/3] SoftwareSerial: fix flush() behaviour Fix #4029 --- .../avr/libraries/SoftwareSerial/SoftwareSerial.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp b/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp index 80df664fa..0a16ff710 100644 --- a/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp +++ b/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -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() From 4878d5c2ecf9fbca8cc9b11d73a02c236393a18e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 11 Nov 2015 16:31:46 +0100 Subject: [PATCH 2/3] WiFi: partially fix flush() behaviour We still need to check if trasmission is completed, BTW this commit should alleviate bugs involving data loss. See #4029 --- libraries/WiFi/src/WiFiClient.cpp | 3 +-- libraries/WiFi/src/WiFiUdp.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index 8fb413499..eb8e6af1d 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -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() { diff --git a/libraries/WiFi/src/WiFiUdp.cpp b/libraries/WiFi/src/WiFiUdp.cpp index 45298c5bc..954024339 100644 --- a/libraries/WiFi/src/WiFiUdp.cpp +++ b/libraries/WiFi/src/WiFiUdp.cpp @@ -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() From b7173ed06c5e207ca5fc68929b05af7141dd9d78 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 11 Nov 2015 16:36:11 +0100 Subject: [PATCH 3/3] Ethernet: partially fix flush() behaviour in EthernetUDP We still need to check if trasmission is completed, BTW this commit should alleviate bugs involving data loss. See #4029 --- libraries/Ethernet/src/EthernetUdp.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libraries/Ethernet/src/EthernetUdp.cpp b/libraries/Ethernet/src/EthernetUdp.cpp index 2baee82df..8066783ae 100644 --- a/libraries/Ethernet/src/EthernetUdp.cpp +++ b/libraries/Ethernet/src/EthernetUdp.cpp @@ -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) { @@ -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 */