Skip to content

Commit

Permalink
WiFiClient - rename flush() to clear() (breaking)
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Nov 11, 2023
1 parent fbfcb80 commit bd5fe04
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void wifiConnectedLoop(){
if(packetLength >= NTP_PACKET_SIZE){
ntpClient.read(ntpPacketBuffer, NTP_PACKET_SIZE);
}
ntpClient.flush();
ntpClient.clear();
uint32_t secsSince1900 = (uint32_t)ntpPacketBuffer[40] << 24 | (uint32_t)ntpPacketBuffer[41] << 16 | (uint32_t)ntpPacketBuffer[42] << 8 | ntpPacketBuffer[43];
//Serial.printf("Seconds since Jan 1 1900: %u\n", secsSince1900);
uint32_t epoch = secsSince1900 - 2208988800UL;
Expand Down
11 changes: 8 additions & 3 deletions libraries/WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class WiFiClientRxBuffer {
return _fill - _pos + r_available();
}

void flush(){
void clear(){
if(r_available()){
fillBuffer();
}
Expand Down Expand Up @@ -465,6 +465,11 @@ size_t WiFiClient::write(Stream &stream)
return written;
}

void WiFiClient::flush()
{

}

int WiFiClient::read(uint8_t *buf, size_t size)
{
int res = -1;
Expand Down Expand Up @@ -507,9 +512,9 @@ int WiFiClient::available()

// Though flushing means to send all pending data,
// seems that in Arduino it also means to clear RX
void WiFiClient::flush() {
void WiFiClient::clear() {
if (_rxBuffer != nullptr) {
_rxBuffer->flush();
_rxBuffer->clear();
}
}

Expand Down
3 changes: 2 additions & 1 deletion libraries/WiFi/src/WiFiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ class WiFiClient : public ESPLwIPClient
size_t write(const uint8_t *buf, size_t size);
size_t write_P(PGM_P buf, size_t size);
size_t write(Stream &stream);
void flush(); // Print::flush tx
int available();
int read();
int read(uint8_t *buf, size_t size);
int peek();
void flush();
void clear(); // clear rx
void stop();
uint8_t connected();

Expand Down
7 changes: 6 additions & 1 deletion libraries/WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ size_t WiFiUDP::write(const uint8_t *buffer, size_t size){
return i;
}

void WiFiUDP::flush()
{

}

int WiFiUDP::parsePacket(){
if(rx_buffer)
return 0;
Expand Down Expand Up @@ -267,7 +272,7 @@ int WiFiUDP::peek(){
return rx_buffer->peek();
}

void WiFiUDP::flush(){
void WiFiUDP::clear(){
if(!rx_buffer) return;
cbuf *b = rx_buffer;
rx_buffer = 0;
Expand Down
3 changes: 2 additions & 1 deletion libraries/WiFi/src/WiFiUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ class WiFiUDP : public UDP {
int endPacket();
size_t write(uint8_t);
size_t write(const uint8_t *buffer, size_t size);
void flush(); // Print::flush tx
int parsePacket();
int available();
int read();
int read(unsigned char* buffer, size_t len);
int read(char* buffer, size_t len);
int peek();
void flush();
void clear(); // clear rx
IPAddress remoteIP();
uint16_t remotePort();
};
Expand Down

0 comments on commit bd5fe04

Please sign in to comment.