From 50d62a229dc82b3fa91c896880e1099710eb151b Mon Sep 17 00:00:00 2001 From: Marcell Date: Wed, 30 Mar 2022 13:59:35 +0200 Subject: [PATCH] Fix erroneous return value of EthernetClient::write() Fix the issue that the method always returned the incoming size parameter regardless of how many bytes were actually sent by EthernetClass::socketSend(). The return value was always wrong if the data size was bigger than the socket buffer size. --- src/EthernetClient.cpp | 6 +++--- src/socket.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EthernetClient.cpp b/src/EthernetClient.cpp index 5a20c748..4198da8b 100644 --- a/src/EthernetClient.cpp +++ b/src/EthernetClient.cpp @@ -83,9 +83,9 @@ size_t EthernetClient::write(uint8_t b) size_t EthernetClient::write(const uint8_t *buf, size_t size) { if (_sockindex >= MAX_SOCK_NUM) return 0; - if (Ethernet.socketSend(_sockindex, buf, size)) return size; - setWriteError(); - return 0; + const size_t bytesSent = Ethernet.socketSend(_sockindex, buf, size); + if (!bytesSent) setWriteError(); + return bytesSent; } int EthernetClient::available() diff --git a/src/socket.cpp b/src/socket.cpp index 7dc83feb..cf4a977d 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -417,7 +417,7 @@ static void write_data(uint8_t s, uint16_t data_offset, const uint8_t *data, uin /** * @brief This function used to send the data in TCP mode - * @return 1 for success else 0. + * @return number of bytes sent for success 0 in case of error. */ uint16_t EthernetClass::socketSend(uint8_t s, const uint8_t * buf, uint16_t len) {