1
0
Fork 0
forked from nuttx/nuttx-update

Update net_timedwait() and net_lockedwait() call sites to handle negated errno in return value

This commit is contained in:
Jussi Kivilinna 2017-09-04 06:55:28 -06:00 committed by Gregory Nutt
parent 23edfe2557
commit 547733cbb0
27 changed files with 79 additions and 90 deletions

View file

@ -199,7 +199,7 @@ int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout)
*/
ret = net_timedwait(&notify->nt_sem, &abstime);
errcode = ((ret < 0) ? get_errno() : 0);
errcode = ((ret < 0) ? -ret : 0);
}
while (ret < 0 && errcode == EINTR);

View file

@ -553,7 +553,7 @@ ssize_t psock_ieee802154_sendto(FAR struct socket *psock, FAR const void *buf,
}
/* If net_lockedwait failed, then we were probably reawakened by a signal. In
* this case, net_lockedwait will have set errno appropriately.
* this case, net_lockedwait will have returned negated errno appropriately.
*/
if (ret < 0)

View file

@ -92,6 +92,8 @@ void igmp_schedmsg(FAR struct igmp_group_s *group, uint8_t msgid)
void igmp_waitmsg(FAR struct igmp_group_s *group, uint8_t msgid)
{
int ret;
/* Schedule to send the message */
net_lock();
@ -105,14 +107,16 @@ void igmp_waitmsg(FAR struct igmp_group_s *group, uint8_t msgid)
{
/* Wait for the semaphore to be posted */
while (net_lockedwait(&group->sem) != 0)
while ((ret = net_lockedwait(&group->sem)) < 0)
{
/* The only error that should occur from net_lockedwait() is if
* the wait is awakened by a signal.
*/
ASSERT(get_errno() == EINTR);
ASSERT(ret == -EINTR);
}
UNUSED(ret);
}
/* The message has been sent and we are no longer waiting */

View file

@ -1131,8 +1131,6 @@ static void inet_recvfrom_initialize(FAR struct socket *psock, FAR void *buf,
#if defined(NET_UDP_HAVE_STACK) || defined(NET_TCP_HAVE_STACK)
static ssize_t inet_recvfrom_result(int result, struct inet_recvfrom_s *pstate)
{
int save_errno = get_errno(); /* In case something we do changes it */
/* Check for a error/timeout detected by the interrupt handler. Errors are
* signaled by negative errno values for the rcv length
*/
@ -1147,12 +1145,12 @@ static ssize_t inet_recvfrom_result(int result, struct inet_recvfrom_s *pstate)
}
/* If net_lockedwait failed, then we were probably reawakened by a signal. In
* this case, net_lockedwait will have set errno appropriately.
* this case, net_lockedwait will have returned negated errno appropriately.
*/
if (result < 0)
{
return -save_errno;
return result;
}
return pstate->ir_recvlen;

View file

@ -89,16 +89,20 @@ static dq_queue_t g_active_pkt_connections;
static inline void _pkt_semtake(sem_t *sem)
{
int ret;
/* Take the semaphore (perhaps waiting) */
while (net_lockedwait(sem) != 0)
while ((ret = net_lockedwait(sem)) < 0)
{
/* The only case that an error should occur here is if
* the wait was awakened by a signal.
*/
DEBUGASSERT(get_errno() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
UNUSED(ret);
}
#define _pkt_semgive(sem) sem_post(sem)

View file

@ -296,8 +296,6 @@ static void pkt_recvfrom_initialize(FAR struct socket *psock, FAR void *buf,
static ssize_t pkt_recvfrom_result(int result, struct pkt_recvfrom_s *pstate)
{
int save_errno = get_errno(); /* In case something we do changes it */
/* Check for a error/timeout detected by the interrupt handler. Errors are
* signaled by negative errno values for the rcv length
*/
@ -312,12 +310,12 @@ static ssize_t pkt_recvfrom_result(int result, struct pkt_recvfrom_s *pstate)
}
/* If net_lockedwait failed, then we were probably reawakened by a signal. In
* this case, net_lockedwait will have set errno appropriately.
* this case, net_lockedwait will have returned negated errno appropriately.
*/
if (result < 0)
{
return -save_errno;
return result;
}
return pstate->pr_recvlen;

View file

@ -309,7 +309,7 @@ ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf,
}
/* If net_lockedwait failed, then we were probably reawakened by a signal. In
* this case, net_lockedwait will have set errno appropriately.
* this case, net_lockedwait will have returned negated errno appropriately.
*/
if (ret < 0)

View file

@ -327,7 +327,7 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
ret = net_lockedwait(&sinfo.s_waitsem);
if (ret < 0)
{
sinfo.s_result = -get_errno();
sinfo.s_result = ret;
}
/* Make sure that no further interrupts are processed */

View file

@ -705,7 +705,7 @@ static int sixlowpan_send_packet(FAR struct socket *psock,
ret = net_lockedwait(&sinfo.s_waitsem);
if (ret < 0)
{
sinfo.s_result = -get_errno();
sinfo.s_result = ret;
}
/* Make sure that no further interrupts are processed */

View file

@ -59,16 +59,20 @@
static void _net_semtake(FAR struct socketlist *list)
{
int ret;
/* Take the semaphore (perhaps waiting) */
while (net_lockedwait(&list->sl_sem) != 0)
while ((ret = net_lockedwait(&list->sl_sem)) < 0)
{
/* The only case that an error should occr here is if
* the wait was awakened by a signal.
*/
DEBUGASSERT(get_errno() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
UNUSED(ret);
}
#define _net_semgive(list) sem_post(&list->sl_sem)

View file

@ -298,20 +298,6 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
*/
ret = net_lockedwait(&state.acpt_sem);
if (ret < 0)
{
/* The value returned by net_lockedwait() the same as the value
* returned by sem_wait(): Zero (OK) is returned on success; -1
* (ERROR) is returned on a failure with the errno value set
* appropriately.
*
* We have to preserve the errno value here because it may be
* altered by intervening operations.
*/
ret = -get_errno();
DEBUGASSERT(ret < 0);
}
/* Make sure that no further events are processed */
@ -335,8 +321,8 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
}
/* If net_lockedwait failed, then we were probably reawakened by a
* signal. In this case, logic above will have set 'ret' to the
* errno value returned by net_lockedwait().
* signal. In this case, net_lockedwait will have returned negated
* errno appropriately.
*/
if (ret < 0)

View file

@ -372,13 +372,9 @@ int psock_tcp_connect(FAR struct socket *psock,
(void)sem_destroy(&state.tc_sem);
/* If net_lockedwait failed, recover the negated error (probably -EINTR) */
/* If net_lockedwait failed, negated errno was returned. */
if (ret < 0)
{
ret = -get_errno();
}
else
if (ret >= 0)
{
/* If the wait succeeded, then get the new error value from
* the state structure

View file

@ -1093,7 +1093,8 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
}
/* If net_lockedwait failed, then we were probably reawakened by a signal.
* In this case, net_lockedwait will have set errno appropriately.
* In this case, net_lockedwait will have returned negated errno
* appropriately.
*/
if (ret < 0)

View file

@ -862,7 +862,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
}
/* If net_lockedwait failed, then we were probably reawakened by a signal. In
* this case, net_lockedwait will have set errno appropriately.
* this case, net_lockedwait will have returned negated errno appropriately.
*/
if (ret < 0)

View file

@ -145,7 +145,7 @@ FAR struct tcp_wrbuffer_s *tcp_wrbuffer_alloc(void)
* buffer
*/
DEBUGVERIFY(net_lockedwait(&g_wrbuffer.sem));
DEBUGVERIFY(net_lockedwait(&g_wrbuffer.sem)); /* TODO: Handle EINTR. */
/* Now, we are guaranteed to have a write buffer structure reserved
* for us in the free list.

View file

@ -107,16 +107,20 @@ static uint16_t g_last_udp_port;
static inline void _udp_semtake(FAR sem_t *sem)
{
int ret;
/* Take the semaphore (perhaps waiting) */
while (net_lockedwait(sem) != 0)
while ((ret = net_lockedwait(sem)) < 0)
{
/* The only case that an error should occur here is if
* the wait was awakened by a signal.
*/
ASSERT(get_errno() == EINTR);
ASSERT(ret == -EINTR);
}
UNUSED(ret);
}
#define _udp_semgive(sem) sem_post(sem)

View file

@ -204,9 +204,9 @@ int usrsock_bind(FAR struct socket *psock,
{
/* Wait for completion of request. */
while (net_lockedwait(&state.recvsem) != OK)
while ((ret = net_lockedwait(&state.recvsem)) < 0)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
ret = state.result;

View file

@ -173,9 +173,9 @@ int usrsock_close(FAR struct usrsock_conn_s *conn)
{
/* Wait for completion of request. */
while (net_lockedwait(&state.recvsem) != OK)
while ((ret = net_lockedwait(&state.recvsem)) < OK)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
ret = state.result;

View file

@ -85,15 +85,17 @@ static dq_queue_t g_active_usrsock_connections;
static void _usrsock_semtake(FAR sem_t *sem)
{
int ret;
/* Take the semaphore (perhaps waiting) */
while (net_lockedwait(sem) != 0)
while ((ret = net_lockedwait(sem)) < 0)
{
/* The only case that an error should occur here is if
* the wait was awakened by a signal.
*/
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
}

View file

@ -228,13 +228,13 @@ int usrsock_connect(FAR struct socket *psock,
{
/* Wait for completion of request (or signal). */
if (net_lockedwait(&state.recvsem) != OK)
ret = net_lockedwait(&state.recvsem);
if (ret < 0)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
/* Wait interrupted, exit early. */
ret = -EINTR;
goto errout_teardown;
}

View file

@ -1026,9 +1026,7 @@ static int usrsockdev_close(FAR struct file *filep)
ret = net_timedwait(&dev->req.sem, &abstime);
if (ret < 0)
{
ret = *get_errno_ptr();
if (ret != ETIMEDOUT && ret != EINTR)
if (ret != -ETIMEDOUT && ret != -EINTR)
{
ninfo("net_timedwait errno: %d\n", ret);
DEBUGASSERT(false);
@ -1179,6 +1177,7 @@ int usrsockdev_do_request(FAR struct usrsock_conn_s *conn,
{
FAR struct usrsockdev_s *dev = conn->dev;
FAR struct usrsock_request_common_s *req_head = iov[0].iov_base;
int ret;
if (!dev)
{
@ -1209,9 +1208,9 @@ int usrsockdev_do_request(FAR struct usrsock_conn_s *conn,
/* Set outstanding request for daemon to handle. */
while (net_lockedwait(&dev->req.sem) != OK)
while ((ret = net_lockedwait(&dev->req.sem)) < 0)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
if (usrsockdev_is_opened(dev))
@ -1228,9 +1227,9 @@ int usrsockdev_do_request(FAR struct usrsock_conn_s *conn,
/* Wait ack for request. */
while (net_lockedwait(&dev->req.acksem) != OK)
while ((ret = net_lockedwait(&dev->req.acksem)) < 0)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
}
else

View file

@ -235,9 +235,9 @@ int usrsock_getsockname(FAR struct socket *psock,
{
/* Wait for completion of request. */
while (net_lockedwait(&state.reqstate.recvsem) != OK)
while ((ret = net_lockedwait(&state.reqstate.recvsem)) < 0)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
ret = state.reqstate.result;

View file

@ -246,9 +246,9 @@ int usrsock_getsockopt(FAR struct usrsock_conn_s *conn, int level, int option,
{
/* Wait for completion of request. */
while (net_lockedwait(&state.reqstate.recvsem) != OK)
while ((ret = net_lockedwait(&state.reqstate.recvsem)) < 0)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
ret = state.reqstate.result;

View file

@ -371,22 +371,18 @@ ssize_t usrsock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Wait for receive-avail (or abort, or timeout, or signal). */
ret = 0;
if (net_timedwait(&state.reqstate.recvsem, ptimeo) != OK)
ret = net_timedwait(&state.reqstate.recvsem, ptimeo);
if (ret < 0)
{
ret = *get_errno_ptr();
if (ret == ETIMEDOUT)
if (ret == -ETIMEDOUT)
{
ninfo("recvfrom timedout\n");
ret = -EAGAIN;
}
else if (ret == EINTR)
else if (ret == -EINTR)
{
ninfo("recvfrom interrupted\n");
ret = -EINTR;
}
else
{
@ -448,9 +444,9 @@ ssize_t usrsock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
{
/* Wait for completion of request. */
while (net_lockedwait(&state.reqstate.recvsem) != OK)
while ((ret = net_lockedwait(&state.reqstate.recvsem)) < 0)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
ret = state.reqstate.result;

View file

@ -334,22 +334,18 @@ ssize_t usrsock_sendto(FAR struct socket *psock, FAR const void *buf,
/* Wait for send-ready (or abort, or timeout, or signal). */
ret = 0;
if (net_timedwait(&state.recvsem, ptimeo) != OK)
ret = net_timedwait(&state.recvsem, ptimeo);
if (ret < 0)
{
ret = *get_errno_ptr();
if (ret == ETIMEDOUT)
if (ret == -ETIMEDOUT)
{
ninfo("sendto timedout\n");
ret = -EAGAIN;
}
else if (ret == EINTR)
else if (ret == -EINTR)
{
ninfo("sendto interrupted\n");
ret = -EINTR;
}
else
{
@ -404,9 +400,9 @@ ssize_t usrsock_sendto(FAR struct socket *psock, FAR const void *buf,
{
/* Wait for completion of request. */
while (net_lockedwait(&state.recvsem) != OK)
while ((ret = net_lockedwait(&state.recvsem)) < 0)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
ret = state.result;

View file

@ -212,9 +212,9 @@ int usrsock_setsockopt(FAR struct usrsock_conn_s *conn, int level, int option,
{
/* Wait for completion of request. */
while (net_lockedwait(&state.recvsem) != OK)
while ((ret = net_lockedwait(&state.recvsem)) < 0)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
ret = state.result;

View file

@ -195,6 +195,7 @@ int usrsock_socket(int domain, int type, int protocol, FAR struct socket *psock)
struct usrsock_reqstate_s state = {};
FAR struct usrsock_conn_s *conn;
int err;
int ret;
/* Allocate the usrsock socket connection structure and save in the new
* socket instance.
@ -230,9 +231,9 @@ int usrsock_socket(int domain, int type, int protocol, FAR struct socket *psock)
/* Wait for completion of request. */
while (net_lockedwait(&state.recvsem) != OK)
while ((ret = net_lockedwait(&state.recvsem)) < 0)
{
DEBUGASSERT(*get_errno_ptr() == EINTR);
DEBUGASSERT(ret == -EINTR);
}
if (state.result < 0)