Skip to content

Commit 50d62a2

Browse files
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.
1 parent 9e63d97 commit 50d62a2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/EthernetClient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ size_t EthernetClient::write(uint8_t b)
8383
size_t EthernetClient::write(const uint8_t *buf, size_t size)
8484
{
8585
if (_sockindex >= MAX_SOCK_NUM) return 0;
86-
if (Ethernet.socketSend(_sockindex, buf, size)) return size;
87-
setWriteError();
88-
return 0;
86+
const size_t bytesSent = Ethernet.socketSend(_sockindex, buf, size);
87+
if (!bytesSent) setWriteError();
88+
return bytesSent;
8989
}
9090

9191
int EthernetClient::available()

src/socket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ static void write_data(uint8_t s, uint16_t data_offset, const uint8_t *data, uin
417417

418418
/**
419419
* @brief This function used to send the data in TCP mode
420-
* @return 1 for success else 0.
420+
* @return number of bytes sent for success 0 in case of error.
421421
*/
422422
uint16_t EthernetClass::socketSend(uint8_t s, const uint8_t * buf, uint16_t len)
423423
{

0 commit comments

Comments
 (0)