net/tcp: Fixed bad return value handling in psock_tcp_send(). send() expects psock_tcp_send() to return a negated errno value, not -1 with the errno set (GN: I added same change for tcp_send_buffered.c which has the same issue as tcp_send_unbuffered.c)

This commit is contained in:
Pelle Windestam 2018-02-13 08:02:42 -06:00 committed by Gregory Nutt
parent 4a36c946e1
commit e0142f1d52
2 changed files with 15 additions and 23 deletions

View File

@ -944,8 +944,6 @@ static inline void send_txnotify(FAR struct socket *psock,
* In this case the process will also receive a SIGPIPE unless
* MSG_NOSIGNAL is set.
*
* Assumptions:
*
****************************************************************************/
ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
@ -954,20 +952,19 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
FAR struct tcp_conn_s *conn;
FAR struct tcp_wrbuffer_s *wrb;
ssize_t result = 0;
int errcode;
int ret = OK;
if (psock == NULL || psock->s_crefs <= 0)
{
nerr("ERROR: Invalid socket\n");
errcode = EBADF;
ret = -EBADF;
goto errout;
}
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(psock->s_flags))
{
nerr("ERROR: Not connected\n");
errcode = ENOTCONN;
ret = -ENOTCONN;
goto errout;
}
@ -1004,7 +1001,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
if (ret < 0)
{
nerr("ERROR: Not reachable\n");
errcode = ENETUNREACH;
ret = -ENETUNREACH;
goto errout;
}
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
@ -1030,7 +1027,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
/* A buffer allocation error occurred */
nerr("ERROR: Failed to allocate write buffer\n");
errcode = ENOMEM;
ret = -ENOMEM;
goto errout_with_lock;
}
@ -1048,7 +1045,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
/* A buffer allocation error occurred */
nerr("ERROR: Failed to allocate callback\n");
errcode = ENOMEM;
ret = -ENOMEM;
goto errout_with_wrb;
}
@ -1100,13 +1097,13 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE);
/* Check for errors. Errors are signalled by negative errno values
/* Check for errors. Errors are signaled by negative errno values
* for the send length
*/
if (result < 0)
{
errcode = result;
ret = result;
goto errout;
}
@ -1117,7 +1114,6 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
if (ret < 0)
{
errcode = -ret;
goto errout;
}
@ -1132,8 +1128,7 @@ errout_with_lock:
net_unlock();
errout:
set_errno(errcode);
return ERROR;
return ret;
}
/****************************************************************************

View File

@ -680,7 +680,7 @@ static inline void send_txnotify(FAR struct socket *psock,
*
* Returned Value:
* On success, returns the number of characters sent. On error,
* -1 is returned, and errno is set appropriately:
* a negated errno value is returned.
*
* EAGAIN or EWOULDBLOCK
* The socket is marked non-blocking and the requested operation
@ -726,7 +726,6 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
{
FAR struct tcp_conn_s *conn;
struct send_s state;
int errcode;
int ret = OK;
/* Verify that the sockfd corresponds to valid, allocated socket */
@ -734,7 +733,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
if (psock == NULL || psock->s_crefs <= 0)
{
nerr("ERROR: Invalid socket\n");
errcode = EBADF;
ret = -EBADF;
goto errout;
}
@ -743,7 +742,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(psock->s_flags))
{
nerr("ERROR: Not connected\n");
errcode = ENOTCONN;
ret = -ENOTCONN;
goto errout;
}
@ -781,7 +780,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
if (ret < 0)
{
nerr("ERROR: Not reachable\n");
errcode = ENETUNREACH;
ret = -ENETUNREACH;
goto errout;
}
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
@ -869,7 +868,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
if (state.snd_sent < 0)
{
errcode = state.snd_sent;
ret = state.snd_sent;
goto errout;
}
@ -879,17 +878,15 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
if (ret < 0)
{
errcode = -ret;
goto errout;
}
/* Return the number of bytes actually sent */
return state.snd_sent;
ret = state.snd_sent;
errout:
set_errno(errcode);
return ERROR;
return ret;
}
/****************************************************************************