net: Ensure sendmsg and sendfile return -EAGAIN in case of timeout

instead of -ETIMEOUT, as specify here:
https://pubs.opengroup.org/onlinepubs/009604599/functions/sendmsg.html
https://man7.org/linux/man-pages/man2/sendfile.2.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-06-27 08:04:32 +08:00 committed by Petro Karashchenko
parent 4f8c8815d6
commit abc72ad128
9 changed files with 32 additions and 8 deletions

View File

@ -439,6 +439,10 @@ ssize_t icmp_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
ret = -ENETUNREACH; ret = -ENETUNREACH;
} }
else
{
ret = -EAGAIN;
}
} }
state.snd_result = ret; state.snd_result = ret;

View File

@ -430,6 +430,10 @@ ssize_t icmpv6_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
ret = -ENETUNREACH; ret = -ENETUNREACH;
} }
else
{
ret = -EAGAIN;
}
} }
state.snd_result = ret; state.snd_result = ret;

View File

@ -258,6 +258,7 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
{ {
if (ret == -ETIMEDOUT) if (ret == -ETIMEDOUT)
{ {
ret = -EAGAIN;
neighbor_notreachable(dev); neighbor_notreachable(dev);
} }

View File

@ -660,6 +660,11 @@ static int sixlowpan_send_packet(FAR struct socket *psock,
ret = net_timedwait(&sinfo.s_waitsem, timeout); ret = net_timedwait(&sinfo.s_waitsem, timeout);
if (ret != -ETIMEDOUT || acked == sinfo.s_acked) if (ret != -ETIMEDOUT || acked == sinfo.s_acked)
{ {
if (ret == -ETIMEDOUT)
{
ret = -EAGAIN;
}
break; /* Timeout without any progress */ break; /* Timeout without any progress */
} }
} }

View File

@ -680,6 +680,11 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
_SO_TIMEOUT(conn->sconn.s_sndtimeo)); _SO_TIMEOUT(conn->sconn.s_sndtimeo));
if (ret != -ETIMEDOUT || acked == state.snd_acked) if (ret != -ETIMEDOUT || acked == state.snd_acked)
{ {
if (ret == -ETIMEDOUT)
{
ret = -EAGAIN;
}
break; /* Timeout without any progress */ break; /* Timeout without any progress */
} }
} }

View File

@ -583,6 +583,11 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile,
&state.snd_sem, _SO_TIMEOUT(conn->sconn.s_sndtimeo)); &state.snd_sem, _SO_TIMEOUT(conn->sconn.s_sndtimeo));
if (ret != -ETIMEDOUT || acked == state.snd_acked) if (ret != -ETIMEDOUT || acked == state.snd_acked)
{ {
if (ret == -ETIMEDOUT)
{
ret = -EAGAIN;
}
break; /* Successful completion or timeout without any progress */ break; /* Successful completion or timeout without any progress */
} }
} }

View File

@ -91,7 +91,7 @@ int file_mq_send(FAR struct file *mq, FAR const char *msg, size_t msglen,
* - Immediately if we are called from an interrupt handler. * - Immediately if we are called from an interrupt handler.
* - Immediately if the message queue is not full, or * - Immediately if the message queue is not full, or
* - After successfully waiting for the message queue to become * - After successfully waiting for the message queue to become
* non-FULL. This would fail with EAGAIN, EINTR, or ETIMEOUT. * non-FULL. This would fail with EAGAIN, EINTR, or ETIMEDOUT.
*/ */
flags = enter_critical_section(); flags = enter_critical_section();

View File

@ -198,11 +198,11 @@ FAR struct mqueue_msg_s *nxmq_alloc_msg(void)
* On success, nxmq_wait_send() returns 0 (OK); a negated errno value is * On success, nxmq_wait_send() returns 0 (OK); a negated errno value is
* returned on any failure: * returned on any failure:
* *
* EAGAIN The queue was full and the O_NONBLOCK flag was set for the * EAGAIN The queue was full and the O_NONBLOCK flag was set for the
* message queue description referred to by msgq. * message queue description referred to by msgq.
* EINTR The call was interrupted by a signal handler. * EINTR The call was interrupted by a signal handler.
* ETIMEOUT A timeout expired before the message queue became non-full * ETIMEDOUT A timeout expired before the message queue became non-full
* (mq_timedsend only). * (mq_timedsend only).
* *
* Assumptions/restrictions: * Assumptions/restrictions:
* - The caller has verified the input parameters using nxmq_verify_send(). * - The caller has verified the input parameters using nxmq_verify_send().
@ -272,7 +272,7 @@ int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)
/* When we resume at this point, either (1) the message queue /* When we resume at this point, either (1) the message queue
* is no longer empty, or (2) the wait has been interrupted by * is no longer empty, or (2) the wait has been interrupted by
* a signal. We can detect the latter case be examining the * a signal. We can detect the latter case be examining the
* per-task errno value (should be EINTR or ETIMEOUT). * per-task errno value (should be EINTR or ETIMEDOUT).
*/ */
if (rtcb->errcode != OK) if (rtcb->errcode != OK)

View File

@ -251,7 +251,7 @@ int file_mq_timedsend(FAR struct file *mq, FAR const char *msg,
ret = nxmq_wait_send(msgq, mq->f_oflags); ret = nxmq_wait_send(msgq, mq->f_oflags);
/* This may return with an error and errno set to either EINTR /* This may return with an error and errno set to either EINTR
* or ETIMEOUT. Cancel the watchdog timer in any event. * or ETIMEDOUT. Cancel the watchdog timer in any event.
*/ */
wd_cancel(&rtcb->waitdog); wd_cancel(&rtcb->waitdog);