diff --git a/net/arp/arp_notify.c b/net/arp/arp_notify.c index ebc7faaea6..e59bca3a55 100644 --- a/net/arp/arp_notify.c +++ b/net/arp/arp_notify.c @@ -199,7 +199,7 @@ int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout) */ ret = net_timedwait(¬ify->nt_sem, &abstime); - errcode = ((ret < 0) ? get_errno() : 0); + errcode = ((ret < 0) ? -ret : 0); } while (ret < 0 && errcode == EINTR); diff --git a/net/ieee802154/ieee802154_sendto.c b/net/ieee802154/ieee802154_sendto.c index 193272724b..d042a86544 100644 --- a/net/ieee802154/ieee802154_sendto.c +++ b/net/ieee802154/ieee802154_sendto.c @@ -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) diff --git a/net/igmp/igmp_msg.c b/net/igmp/igmp_msg.c index 0f8b1fb9c5..348b0dd571 100644 --- a/net/igmp/igmp_msg.c +++ b/net/igmp/igmp_msg.c @@ -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 */ diff --git a/net/inet/inet_recvfrom.c b/net/inet/inet_recvfrom.c index 0adc679529..7035d71a5f 100644 --- a/net/inet/inet_recvfrom.c +++ b/net/inet/inet_recvfrom.c @@ -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; diff --git a/net/pkt/pkt_conn.c b/net/pkt/pkt_conn.c index 599fe63371..cc4954a1ec 100644 --- a/net/pkt/pkt_conn.c +++ b/net/pkt/pkt_conn.c @@ -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) diff --git a/net/pkt/pkt_recvfrom.c b/net/pkt/pkt_recvfrom.c index da23e1c70e..bb5523c349 100644 --- a/net/pkt/pkt_recvfrom.c +++ b/net/pkt/pkt_recvfrom.c @@ -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; diff --git a/net/pkt/pkt_send.c b/net/pkt/pkt_send.c index d8c9bffc7b..3e37167ff2 100644 --- a/net/pkt/pkt_send.c +++ b/net/pkt/pkt_send.c @@ -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) diff --git a/net/sixlowpan/sixlowpan_send.c b/net/sixlowpan/sixlowpan_send.c index d006ccbd55..3fe52d0743 100644 --- a/net/sixlowpan/sixlowpan_send.c +++ b/net/sixlowpan/sixlowpan_send.c @@ -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 */ diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index f987ccff3a..612031a81d 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -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 */ diff --git a/net/socket/net_sockets.c b/net/socket/net_sockets.c index ceac793ee8..fbf38ed548 100644 --- a/net/socket/net_sockets.c +++ b/net/socket/net_sockets.c @@ -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) diff --git a/net/tcp/tcp_accept.c b/net/tcp/tcp_accept.c index 17bae962fe..45fd7c1309 100644 --- a/net/tcp/tcp_accept.c +++ b/net/tcp/tcp_accept.c @@ -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) diff --git a/net/tcp/tcp_connect.c b/net/tcp/tcp_connect.c index e4f4d1351c..80317d4427 100644 --- a/net/tcp/tcp_connect.c +++ b/net/tcp/tcp_connect.c @@ -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 diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 7f797f2c34..c9c6a2d3ff 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -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) diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index 006429d7a6..5464c0e107 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -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) diff --git a/net/tcp/tcp_wrbuffer.c b/net/tcp/tcp_wrbuffer.c index 3947d5294e..29fba3ddce 100644 --- a/net/tcp/tcp_wrbuffer.c +++ b/net/tcp/tcp_wrbuffer.c @@ -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. diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c index 35099f4776..47923ccf44 100644 --- a/net/udp/udp_conn.c +++ b/net/udp/udp_conn.c @@ -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) diff --git a/net/usrsock/usrsock_bind.c b/net/usrsock/usrsock_bind.c index d8c9456719..b86bb5aa6a 100644 --- a/net/usrsock/usrsock_bind.c +++ b/net/usrsock/usrsock_bind.c @@ -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; diff --git a/net/usrsock/usrsock_close.c b/net/usrsock/usrsock_close.c index 8933892811..337218dcfe 100644 --- a/net/usrsock/usrsock_close.c +++ b/net/usrsock/usrsock_close.c @@ -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; diff --git a/net/usrsock/usrsock_conn.c b/net/usrsock/usrsock_conn.c index 21baa26da7..b22762b3d5 100644 --- a/net/usrsock/usrsock_conn.c +++ b/net/usrsock/usrsock_conn.c @@ -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); } } diff --git a/net/usrsock/usrsock_connect.c b/net/usrsock/usrsock_connect.c index 45ed8c1dd6..ffd9b078cc 100644 --- a/net/usrsock/usrsock_connect.c +++ b/net/usrsock/usrsock_connect.c @@ -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; } diff --git a/net/usrsock/usrsock_dev.c b/net/usrsock/usrsock_dev.c index 11b915e0d8..0bf4a949d4 100644 --- a/net/usrsock/usrsock_dev.c +++ b/net/usrsock/usrsock_dev.c @@ -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 diff --git a/net/usrsock/usrsock_getsockname.c b/net/usrsock/usrsock_getsockname.c index b8554a9bab..5c755eb9c3 100644 --- a/net/usrsock/usrsock_getsockname.c +++ b/net/usrsock/usrsock_getsockname.c @@ -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; diff --git a/net/usrsock/usrsock_getsockopt.c b/net/usrsock/usrsock_getsockopt.c index a3ca0a1594..5d98976587 100644 --- a/net/usrsock/usrsock_getsockopt.c +++ b/net/usrsock/usrsock_getsockopt.c @@ -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; diff --git a/net/usrsock/usrsock_recvfrom.c b/net/usrsock/usrsock_recvfrom.c index dbf8034b59..a2647129ab 100644 --- a/net/usrsock/usrsock_recvfrom.c +++ b/net/usrsock/usrsock_recvfrom.c @@ -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; diff --git a/net/usrsock/usrsock_sendto.c b/net/usrsock/usrsock_sendto.c index 108089534b..bcd6aeb92a 100644 --- a/net/usrsock/usrsock_sendto.c +++ b/net/usrsock/usrsock_sendto.c @@ -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; diff --git a/net/usrsock/usrsock_setsockopt.c b/net/usrsock/usrsock_setsockopt.c index 3dbd078ac2..edd3e11c22 100644 --- a/net/usrsock/usrsock_setsockopt.c +++ b/net/usrsock/usrsock_setsockopt.c @@ -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; diff --git a/net/usrsock/usrsock_socket.c b/net/usrsock/usrsock_socket.c index 63c4424f28..dff88f625c 100644 --- a/net/usrsock/usrsock_socket.c +++ b/net/usrsock/usrsock_socket.c @@ -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)