The OSAL interface already provides an abstraction for opening sockets via osal_socket(), but closing sockets is currently done directly with close() in the CoAP client/server code.
This creates an inconsistency in the OS abstraction layer: socket creation is platform-independent through OSAL, while socket cleanup still depends directly on the platform socket API.
Current behavior
The CoAP client and server directly call close() when stopping or when socket setup fails.
Examples:
close(m_sock);
close(m_sockfd);
close(sockfd);
Proposed change
Add a new OSAL function:
osal_basetype_t osal_socket_close(osal_socket_handle_t sockd);
and implement it for the existing OSAL backends:
- Linux
- FreeRTOS
- EFR32 Wi-SUN
Then replace direct calls to close() in the CoAP client/server code with osal_socket_close().
Motivation
This keeps socket lifecycle handling consistently behind the OSAL interface:
osal_socket() for opening sockets
osal_socket_close() for closing sockets
This also makes the code more portable for platforms where closing a socket may require a different platform-specific API or wrapper.
Expected impact
The change should preserve the existing behavior on platforms where close() is already used, while improving portability and consistency of the OSAL interface.
The OSAL interface already provides an abstraction for opening sockets via
osal_socket(), but closing sockets is currently done directly withclose()in the CoAP client/server code.This creates an inconsistency in the OS abstraction layer: socket creation is platform-independent through OSAL, while socket cleanup still depends directly on the platform socket API.
Current behavior
The CoAP client and server directly call
close()when stopping or when socket setup fails.Examples:
Proposed change
Add a new OSAL function:
and implement it for the existing OSAL backends:
Then replace direct calls to
close()in the CoAP client/server code withosal_socket_close().Motivation
This keeps socket lifecycle handling consistently behind the OSAL interface:
osal_socket()for opening socketsosal_socket_close()for closing socketsThis also makes the code more portable for platforms where closing a socket may require a different platform-specific API or wrapper.
Expected impact
The change should preserve the existing behavior on platforms where
close()is already used, while improving portability and consistency of the OSAL interface.