Ethernet icon indicating copy to clipboard operation
Ethernet copied to clipboard

Fix the write function to return the actual number of bytes sent.

Open BetterComputing opened this issue 1 year ago • 2 comments

The write function was always returning the same count of bytes as was passed in because the size variable was not being assigned the actual number of bytes sent. For example, if I am using a WIZNet 5500 (which limits the send size to 2048 bytes) and I call the function as follows:

size_t bytesSent = pClient->write(pBuffer, 8192);

The result returned into the variable bytesSent will be 8192, even though only 2048 bytes were actually sent.

The change to EthernetClient.cpp in this fork fixes the bug.

BetterComputing avatar Nov 23 '23 02:11 BetterComputing

Memory usage change @ fdec9ee314aa34fdb8a2c3446af807c15cedfde8

Board flash % RAM for global variables %
arduino:avr:leonardo :green_heart: -14 - 0 -0.05 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:mega :green_heart: -14 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:nano :green_heart: -14 - 0 -0.05 - 0.0 0 - 0 0.0 - 0.0
arduino:megaavr:nona4809 :grey_question: -14 - +8 -0.03 - +0.02 0 - 0 0.0 - 0.0
arduino:megaavr:uno2018 :grey_question: -14 - +8 -0.03 - +0.02 0 - 0 0.0 - 0.0
arduino:sam:arduino_due_x_dbg :green_heart: -8 - 0 -0.0 - 0.0 N/A N/A
arduino:samd:arduino_zero_edbg :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkr1000 :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrfox1200 :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrgsm1400 :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrnb1500 :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrvidor4000 :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1300 :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1310 :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwifi1010 :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrzero :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot :green_heart: -4 - 0 -0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/AdvancedChatServer
flash
% examples/AdvancedChatServer
RAM for global variables
% examples/BarometricPressureWebServer
flash
% examples/BarometricPressureWebServer
RAM for global variables
% examples/ChatServer
flash
% examples/ChatServer
RAM for global variables
% examples/DhcpAddressPrinter
flash
% examples/DhcpAddressPrinter
RAM for global variables
% examples/DhcpChatServer
flash
% examples/DhcpChatServer
RAM for global variables
% examples/LinkStatus
flash
% examples/LinkStatus
RAM for global variables
% examples/PagerServer
flash
% examples/PagerServer
RAM for global variables
% examples/TelnetClient
flash
% examples/TelnetClient
RAM for global variables
% examples/UDPSendReceiveString
flash
% examples/UDPSendReceiveString
RAM for global variables
% examples/UdpNtpClient
flash
% examples/UdpNtpClient
RAM for global variables
% examples/WebClient
flash
% examples/WebClient
RAM for global variables
% examples/WebClientRepeating
flash
% examples/WebClientRepeating
RAM for global variables
% examples/WebServer
flash
% examples/WebServer
RAM for global variables
%
arduino:avr:leonardo -14 -0.05 0 0.0 -14 -0.05 0 0.0 -14 -0.05 0 0.0 0 0.0 0 0.0 -14 -0.05 0 0.0 0 0.0 0 0.0 -14 -0.05 0 0.0 -10 -0.03 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 -10 -0.03 0 0.0 -10 -0.03 0 0.0 -14 -0.05 0 0.0
arduino:avr:mega -14 -0.01 0 0.0 -14 -0.01 0 0.0 -14 -0.01 0 0.0 0 0.0 0 0.0 -14 -0.01 0 0.0 0 0.0 0 0.0 -14 -0.01 0 0.0 -10 -0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 -10 -0.0 0 0.0 -10 -0.0 0 0.0 -14 -0.01 0 0.0
arduino:avr:nano -14 -0.05 0 0.0 -14 -0.05 0 0.0 -14 -0.05 0 0.0 0 0.0 0 0.0 -14 -0.05 0 0.0 0 0.0 0 0.0 -14 -0.05 0 0.0 -10 -0.03 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 -10 -0.03 0 0.0 -10 -0.03 0 0.0 -14 -0.05 0 0.0
arduino:megaavr:nona4809 -14 -0.03 0 0.0 -14 -0.03 0 0.0 -14 -0.03 0 0.0 0 0.0 0 0.0 -14 -0.03 0 0.0 0 0.0 0 0.0 -14 -0.03 0 0.0 8 0.02 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 8 0.02 0 0.0 8 0.02 0 0.0 -14 -0.03 0 0.0
arduino:megaavr:uno2018 -14 -0.03 0 0.0 -14 -0.03 0 0.0 -14 -0.03 0 0.0 0 0.0 0 0.0 -14 -0.03 0 0.0 0 0.0 0 0.0 -14 -0.03 0 0.0 8 0.02 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 8 0.02 0 0.0 8 0.02 0 0.0 -14 -0.03 0 0.0
arduino:sam:arduino_due_x_dbg -8 -0.0 N/A N/A -8 -0.0 N/A N/A -8 -0.0 N/A N/A 0 0.0 N/A N/A -8 -0.0 N/A N/A 0 0.0 N/A N/A -8 -0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A -8 -0.0 N/A N/A -8 -0.0 N/A N/A -8 -0.0 N/A N/A
arduino:samd:arduino_zero_edbg -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0
arduino:samd:mkr1000 -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 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 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0
arduino:samd:mkrwan1310 -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0
arduino:samd:mkrwifi1010 -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0
arduino:samd:mkrzero -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0
arduino:samd:nano_33_iot -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0 -4 -0.0 0 0.0
Click for full report CSV
Board,examples/AdvancedChatServer<br>flash,%,examples/AdvancedChatServer<br>RAM for global variables,%,examples/BarometricPressureWebServer<br>flash,%,examples/BarometricPressureWebServer<br>RAM for global variables,%,examples/ChatServer<br>flash,%,examples/ChatServer<br>RAM for global variables,%,examples/DhcpAddressPrinter<br>flash,%,examples/DhcpAddressPrinter<br>RAM for global variables,%,examples/DhcpChatServer<br>flash,%,examples/DhcpChatServer<br>RAM for global variables,%,examples/LinkStatus<br>flash,%,examples/LinkStatus<br>RAM for global variables,%,examples/PagerServer<br>flash,%,examples/PagerServer<br>RAM for global variables,%,examples/TelnetClient<br>flash,%,examples/TelnetClient<br>RAM for global variables,%,examples/UDPSendReceiveString<br>flash,%,examples/UDPSendReceiveString<br>RAM for global variables,%,examples/UdpNtpClient<br>flash,%,examples/UdpNtpClient<br>RAM for global variables,%,examples/WebClient<br>flash,%,examples/WebClient<br>RAM for global variables,%,examples/WebClientRepeating<br>flash,%,examples/WebClientRepeating<br>RAM for global variables,%,examples/WebServer<br>flash,%,examples/WebServer<br>RAM for global variables,%
arduino:avr:leonardo,-14,-0.05,0,0.0,-14,-0.05,0,0.0,-14,-0.05,0,0.0,0,0.0,0,0.0,-14,-0.05,0,0.0,0,0.0,0,0.0,-14,-0.05,0,0.0,-10,-0.03,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-10,-0.03,0,0.0,-10,-0.03,0,0.0,-14,-0.05,0,0.0
arduino:avr:mega,-14,-0.01,0,0.0,-14,-0.01,0,0.0,-14,-0.01,0,0.0,0,0.0,0,0.0,-14,-0.01,0,0.0,0,0.0,0,0.0,-14,-0.01,0,0.0,-10,-0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-10,-0.0,0,0.0,-10,-0.0,0,0.0,-14,-0.01,0,0.0
arduino:avr:nano,-14,-0.05,0,0.0,-14,-0.05,0,0.0,-14,-0.05,0,0.0,0,0.0,0,0.0,-14,-0.05,0,0.0,0,0.0,0,0.0,-14,-0.05,0,0.0,-10,-0.03,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-10,-0.03,0,0.0,-10,-0.03,0,0.0,-14,-0.05,0,0.0
arduino:megaavr:nona4809,-14,-0.03,0,0.0,-14,-0.03,0,0.0,-14,-0.03,0,0.0,0,0.0,0,0.0,-14,-0.03,0,0.0,0,0.0,0,0.0,-14,-0.03,0,0.0,8,0.02,0,0.0,0,0.0,0,0.0,0,0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.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0
arduino:samd:mkrzero,-4,-0.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0,0,0.0,0,0.0,-4,-0.0,0,0.0,0,0.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0
arduino:samd:nano_33_iot,-4,-0.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0,0,0.0,0,0.0,-4,-0.0,0,0.0,0,0.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0,-4,-0.0,0,0.0

github-actions[bot] avatar Nov 23 '23 02:11 github-actions[bot]

Thanks @BetterComputing. For the sake of making the information available to the reviewers, I'll note here the two other alternative proposals that have been submitted for fixing this bug:

  • https://github.com/arduino-libraries/Ethernet/pull/142
  • https://github.com/arduino-libraries/Ethernet/pull/187

per1234 avatar Nov 23 '23 06:11 per1234