Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect status reporting from OS_SocketSendTo_Impl #1243

Closed
shuq0 opened this issue Apr 1, 2022 · 2 comments
Closed

Incorrect status reporting from OS_SocketSendTo_Impl #1243

shuq0 opened this issue Apr 1, 2022 · 2 comments
Labels

Comments

@shuq0
Copy link

shuq0 commented Apr 1, 2022

Describe the bug
The return value of sendto returns the number of characters sent on success and -1 on error. In OS_SocketSendTo_Impl the return of sendto is being assigned as os_status and returned. This results in a non-zero (OS_SUCCESS) status being reported back to the calling function which is interpreted as an error

To Reproduce
Steps to reproduce the behavior:

  1. Put breakpoint on OS_SocketSendTo_Impl
  2. Enable TO output using cmdUtil
  3. Chaeck the value of os_result

Expected behavior
os_result should be OS_SUCCESS if the return value of sendto != buflen.

Code snips

osal/src/os/portable/os-impl-bsd-sockets.c

OS_SocketSendTo_Impl { ...

 os_result = sendto(impl->fd, buffer, buflen, MSG_DONTWAIT, sa, addrlen);
    if (os_result < 0)
    {
        OS_DEBUG("sendto: %s\n", strerror(errno));
        return OS_ERROR;
    }

    return os_result;
...

Reporter Info
Syed Huq, Kepler Communications.

@skliper
Copy link
Contributor

skliper commented Apr 4, 2022

Not really clear what makes the current behavior "incorrect". OS_SocketSendTo documents the current behavior:

/**
* @brief Sends data to a message-oriented (datagram) socket
*
* This sends data in a non-blocking mode. If the socket is not currently able to
* queue the message, such as if its outbound buffer is full, then this returns
* an error code.
*
* @param[in] sock_id The socket ID, which must be of the datagram type
* @param[in] buffer Pointer to message data to send @nonnull
* @param[in] buflen The length of the message data to send @nonzero
* @param[in] RemoteAddr Buffer containing the remote network address to send to
*
* @return Count of actual bytes sent or error status, see @ref OSReturnCodes
* @retval #OS_INVALID_POINTER if argument is NULL
* @retval #OS_ERR_INVALID_SIZE if passed-in buflen is not valid
* @retval #OS_ERR_INVALID_ID if the sock_id parameter is not valid
* @retval #OS_ERR_INCORRECT_OBJ_TYPE if the handle is not a socket
*/

This results in a non-zero (OS_SUCCESS) status being reported back to the calling function which is interpreted as an error

The API is documented as returning actual bytes sent, so the calling function should handle positive return values.

@skliper skliper added the invalid label Apr 4, 2022
@shuq0 shuq0 closed this as completed Apr 4, 2022
@shuq0
Copy link
Author

shuq0 commented Apr 4, 2022

Thanks for the clarification, fixed the calling function to account for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants