mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 10:58:49 +08:00
net/sockets: psock_sendto() is an internal OS interface an should not set the errno variable.
This commit is contained in:
parent
8a75add6a0
commit
9e8529b1d0
3 changed files with 18 additions and 26 deletions
|
@ -162,12 +162,12 @@ static int rpcclnt_send(FAR struct rpcclnt *rpc, int procid, int prog,
|
|||
FAR void *call, int reqlen)
|
||||
{
|
||||
ssize_t nbytes;
|
||||
int error = OK;
|
||||
int ret = OK;
|
||||
|
||||
/* Send the call message
|
||||
*
|
||||
* On success, psock_sendto returns the number of bytes sent;
|
||||
* On failure, it returns -1 with the specific error in errno.
|
||||
* On failure, it returns a negated errno value.
|
||||
*/
|
||||
|
||||
nbytes = psock_sendto(rpc->rc_so, call, reqlen, 0,
|
||||
|
@ -176,11 +176,11 @@ static int rpcclnt_send(FAR struct rpcclnt *rpc, int procid, int prog,
|
|||
{
|
||||
/* psock_sendto failed */
|
||||
|
||||
error = get_errno();
|
||||
ferr("ERROR: psock_sendto failed: %d\n", error);
|
||||
ret = (int)-nbytes;
|
||||
ferr("ERROR: psock_sendto failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return error;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -775,8 +775,8 @@ ssize_t psock_send(FAR struct socket *psock, const void *buf, size_t len,
|
|||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* -1 is returned, and errno is set appropriately:
|
||||
* On success, returns the number of characters sent. On a negated errno
|
||||
* value is returned. One of:
|
||||
*
|
||||
* EAGAIN or EWOULDBLOCK
|
||||
* The socket is marked non-blocking and the requested operation
|
||||
|
@ -818,8 +818,6 @@ ssize_t psock_send(FAR struct socket *psock, const void *buf, size_t len,
|
|||
* In this case the process will also receive a SIGPIPE unless
|
||||
* MSG_NOSIGNAL is set.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
|
|
|
@ -73,8 +73,8 @@
|
|||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* -1 is returned, and errno is set appropriately:
|
||||
* On success, returns the number of characters sent. On a negated errno
|
||||
* value is returned. One of:
|
||||
*
|
||||
* EAGAIN or EWOULDBLOCK
|
||||
* The socket is marked non-blocking and the requested operation
|
||||
|
@ -116,8 +116,6 @@
|
|||
* In this case the process will also receive a SIGPIPE unless
|
||||
* MSG_NOSIGNAL is set.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
|
@ -125,7 +123,6 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
socklen_t tolen)
|
||||
{
|
||||
ssize_t nsent;
|
||||
int errcode;
|
||||
|
||||
DEBUGASSERT(psock != NULL && buf != NULL);
|
||||
|
||||
|
@ -140,8 +137,7 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
return psock_send(psock, buf, len, flags);
|
||||
#else
|
||||
nerr("ERROR: No 'to' address\n");
|
||||
errcode = EINVAL;
|
||||
goto errout;
|
||||
return -EINVAL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -150,8 +146,7 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
if (psock == NULL || psock->s_crefs <= 0)
|
||||
{
|
||||
nerr("ERROR: Invalid socket\n");
|
||||
errcode = EBADF;
|
||||
goto errout;
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
/* Let the address family's sendto() method handle the operation */
|
||||
|
@ -164,15 +159,10 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
if (nsent < 0)
|
||||
{
|
||||
nerr("ERROR: Family-specific send failed: %ld\n", (long)nsent);
|
||||
errcode = -nsent;
|
||||
goto errout;
|
||||
return nsent;
|
||||
}
|
||||
|
||||
return nsent;
|
||||
|
||||
errout:
|
||||
set_errno(errcode);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -236,8 +226,6 @@ errout:
|
|||
* In this case the process will also receive a SIGPIPE unless
|
||||
* MSG_NOSIGNAL is set.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t sendto(int sockfd, FAR const void *buf, size_t len, int flags,
|
||||
|
@ -257,6 +245,12 @@ ssize_t sendto(int sockfd, FAR const void *buf, size_t len, int flags,
|
|||
/* And let psock_sendto do all of the work */
|
||||
|
||||
ret = psock_sendto(psock, buf, len, flags, to, tolen);
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno((int)-ret);
|
||||
ret = ERROR;
|
||||
}
|
||||
|
||||
leave_cancellation_point();
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue