diff --git a/fs/nfs/rpc_clnt.c b/fs/nfs/rpc_clnt.c index 2432a94c03d..e5028fe1a97 100644 --- a/fs/nfs/rpc_clnt.c +++ b/fs/nfs/rpc_clnt.c @@ -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; } /**************************************************************************** diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 2ea1b3da0fa..848bddf4b4f 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -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, diff --git a/net/socket/sendto.c b/net/socket/sendto.c index 341a7ecdc27..2325e46ff22 100644 --- a/net/socket/sendto.c +++ b/net/socket/sendto.c @@ -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; }