Skip to content

Add OSAL abstraction for closing sockets #47

@mzella-ll

Description

@mzella-ll

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions