Skip to content

Refactor: Replace goto statements in socketBegin with findAvailableSocket helper#295

Open
kaabia wants to merge 1 commit intoarduino-libraries:masterfrom
kaabia:refactor/socket-find-available-no-goto
Open

Refactor: Replace goto statements in socketBegin with findAvailableSocket helper#295
kaabia wants to merge 1 commit intoarduino-libraries:masterfrom
kaabia:refactor/socket-find-available-no-goto

Conversation

@kaabia
Copy link
Copy Markdown

@kaabia kaabia commented Nov 9, 2025

This is a major structural cleanup. It extracts the complex logic for checking socket status, finding a CLOSED socket, and forcibly closing CLOSING sockets into a separate helper function (findAvailableSocket). This eliminates all goto statements in socketBegin and socketBeginMulticast, greatly improving readability and maintainability.

…cket helper

This is a major structural cleanup. It extracts the complex logic for
checking socket status, finding a CLOSED socket, and forcibly closing
CLOSING sockets into a separate helper function (findAvailableSocket).
This eliminates all goto statements in socketBegin and
socketBeginMulticast, greatly improving readability and maintainability.

Signed-off-by: Badr Bacem KAABIA <badrbacemkaabia@gmail.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 9, 2025

Memory usage change @ 5dc44d6

Board flash % RAM for global variables %
arduino:avr:leonardo 💚 -100 - 0 -0.35 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:mega 💚 -98 - 0 -0.04 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:nano 💚 -88 - 0 -0.29 - 0.0 0 - 0 0.0 - 0.0
arduino:megaavr:nona4809 💚 -78 - 0 -0.16 - 0.0 0 - 0 0.0 - 0.0
arduino:megaavr:uno2018 💚 -78 - 0 -0.16 - 0.0 0 - 0 0.0 - 0.0
arduino:sam:arduino_due_x_dbg 💚 -32 - 0 -0.01 - 0.0 N/A N/A
arduino:samd:arduino_zero_edbg 💚 -24 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkr1000 💚 -24 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrfox1200 💚 -24 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrgsm1400 💚 -24 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrnb1500 💚 -24 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrvidor4000 💚 -24 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1300 💚 -24 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1310 💚 -24 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwifi1010 💚 -24 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrzero 💚 -24 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot 💚 -24 - 0 -0.01 - 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 -100 -0.35 0 0.0 -100 -0.35 0 0.0 -100 -0.35 0 0.0 -90 -0.31 0 0.0 -100 -0.35 0 0.0 0 0.0 0 0.0 -100 -0.35 0 0.0 -100 -0.35 0 0.0 -90 -0.31 0 0.0 -90 -0.31 0 0.0 -100 -0.35 0 0.0 -100 -0.35 0 0.0 -100 -0.35 0 0.0
arduino:avr:mega -98 -0.04 0 0.0 -98 -0.04 0 0.0 -98 -0.04 0 0.0 -88 -0.03 0 0.0 -98 -0.04 0 0.0 0 0.0 0 0.0 -98 -0.04 0 0.0 -98 -0.04 0 0.0 -88 -0.03 0 0.0 -88 -0.03 0 0.0 -98 -0.04 0 0.0 -98 -0.04 0 0.0 -98 -0.04 0 0.0
arduino:avr:nano -80 -0.26 0 0.0 -80 -0.26 0 0.0 -80 -0.26 0 0.0 -88 -0.29 0 0.0 -80 -0.26 0 0.0 0 0.0 0 0.0 -80 -0.26 0 0.0 -80 -0.26 0 0.0 -88 -0.29 0 0.0 -88 -0.29 0 0.0 -80 -0.26 0 0.0 -80 -0.26 0 0.0 -80 -0.26 0 0.0
arduino:megaavr:nona4809 -78 -0.16 0 0.0 -78 -0.16 0 0.0 -78 -0.16 0 0.0 -74 -0.15 0 0.0 -78 -0.16 0 0.0 0 0.0 0 0.0 -78 -0.16 0 0.0 -78 -0.16 0 0.0 -74 -0.15 0 0.0 -74 -0.15 0 0.0 -78 -0.16 0 0.0 -78 -0.16 0 0.0 -78 -0.16 0 0.0
arduino:megaavr:uno2018 -78 -0.16 0 0.0 -78 -0.16 0 0.0 -78 -0.16 0 0.0 -74 -0.15 0 0.0 -78 -0.16 0 0.0 0 0.0 0 0.0 -78 -0.16 0 0.0 -78 -0.16 0 0.0 -74 -0.15 0 0.0 -74 -0.15 0 0.0 -78 -0.16 0 0.0 -78 -0.16 0 0.0 -78 -0.16 0 0.0
arduino:sam:arduino_due_x_dbg -32 -0.01 N/A N/A -24 -0.0 N/A N/A -32 -0.01 N/A N/A -32 -0.01 N/A N/A -24 -0.0 N/A N/A 0 0.0 N/A N/A -32 -0.01 N/A N/A -24 -0.0 N/A N/A -24 -0.0 N/A N/A -24 -0.0 N/A N/A -32 -0.01 N/A N/A -32 -0.01 N/A N/A -32 -0.01 N/A N/A
arduino:samd:arduino_zero_edbg -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0
arduino:samd:mkr1000 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0
arduino:samd:mkrfox1200 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0
arduino:samd:mkrgsm1400 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0
arduino:samd:mkrnb1500 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0
arduino:samd:mkrvidor4000 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0
arduino:samd:mkrwan1300 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0
arduino:samd:mkrwan1310 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0
arduino:samd:mkrwifi1010 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0
arduino:samd:mkrzero -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0
arduino:samd:nano_33_iot -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 0 0.0 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 0 0.0 -24 -0.01 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,-100,-0.35,0,0.0,-100,-0.35,0,0.0,-100,-0.35,0,0.0,-90,-0.31,0,0.0,-100,-0.35,0,0.0,0,0.0,0,0.0,-100,-0.35,0,0.0,-100,-0.35,0,0.0,-90,-0.31,0,0.0,-90,-0.31,0,0.0,-100,-0.35,0,0.0,-100,-0.35,0,0.0,-100,-0.35,0,0.0
arduino:avr:mega,-98,-0.04,0,0.0,-98,-0.04,0,0.0,-98,-0.04,0,0.0,-88,-0.03,0,0.0,-98,-0.04,0,0.0,0,0.0,0,0.0,-98,-0.04,0,0.0,-98,-0.04,0,0.0,-88,-0.03,0,0.0,-88,-0.03,0,0.0,-98,-0.04,0,0.0,-98,-0.04,0,0.0,-98,-0.04,0,0.0
arduino:avr:nano,-80,-0.26,0,0.0,-80,-0.26,0,0.0,-80,-0.26,0,0.0,-88,-0.29,0,0.0,-80,-0.26,0,0.0,0,0.0,0,0.0,-80,-0.26,0,0.0,-80,-0.26,0,0.0,-88,-0.29,0,0.0,-88,-0.29,0,0.0,-80,-0.26,0,0.0,-80,-0.26,0,0.0,-80,-0.26,0,0.0
arduino:megaavr:nona4809,-78,-0.16,0,0.0,-78,-0.16,0,0.0,-78,-0.16,0,0.0,-74,-0.15,0,0.0,-78,-0.16,0,0.0,0,0.0,0,0.0,-78,-0.16,0,0.0,-78,-0.16,0,0.0,-74,-0.15,0,0.0,-74,-0.15,0,0.0,-78,-0.16,0,0.0,-78,-0.16,0,0.0,-78,-0.16,0,0.0
arduino:megaavr:uno2018,-78,-0.16,0,0.0,-78,-0.16,0,0.0,-78,-0.16,0,0.0,-74,-0.15,0,0.0,-78,-0.16,0,0.0,0,0.0,0,0.0,-78,-0.16,0,0.0,-78,-0.16,0,0.0,-74,-0.15,0,0.0,-74,-0.15,0,0.0,-78,-0.16,0,0.0,-78,-0.16,0,0.0,-78,-0.16,0,0.0
arduino:sam:arduino_due_x_dbg,-32,-0.01,N/A,N/A,-24,-0.0,N/A,N/A,-32,-0.01,N/A,N/A,-32,-0.01,N/A,N/A,-24,-0.0,N/A,N/A,0,0.0,N/A,N/A,-32,-0.01,N/A,N/A,-24,-0.0,N/A,N/A,-24,-0.0,N/A,N/A,-24,-0.0,N/A,N/A,-32,-0.01,N/A,N/A,-32,-0.01,N/A,N/A,-32,-0.01,N/A,N/A
arduino:samd:arduino_zero_edbg,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0
arduino:samd:mkr1000,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0
arduino:samd:mkrfox1200,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0
arduino:samd:mkrgsm1400,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0
arduino:samd:mkrnb1500,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0
arduino:samd:mkrvidor4000,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0
arduino:samd:mkrwan1300,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0
arduino:samd:mkrwan1310,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0
arduino:samd:mkrwifi1010,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0
arduino:samd:mkrzero,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0
arduino:samd:nano_33_iot,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,0,0.0,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0,-24,-0.01,0,0.0

@per1234 per1234 added topic: code Related to content of the project itself type: enhancement Proposed improvement labels Nov 12, 2025
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 4, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: code Related to content of the project itself type: enhancement Proposed improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants