From b3a86b681e90f212a78ab8ed0991c5f991fd030e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 25 Jan 2015 17:53:01 -0600 Subject: Replace an un-necessary goto --- nuttx/net/local/local_accept.c | 112 ++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/nuttx/net/local/local_accept.c b/nuttx/net/local/local_accept.c index e1406168a..b7dc623a0 100644 --- a/nuttx/net/local/local_accept.c +++ b/nuttx/net/local/local_accept.c @@ -83,6 +83,7 @@ int psock_local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, { FAR struct local_conn_s *server; FAR struct local_conn_s *client; + int ret; /* Some sanity checks */ @@ -96,83 +97,82 @@ int psock_local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, return -EOPNOTSUPP; } - /* Are there pending connections. Remove the client from the - * head of the waiting list. - */ + /* Loop as necessary if we have to wait for a connection */ -try_again: + for (;;) + { + /* Are there pending connections. Remove the client from the + * head of the waiting list. + */ - client = (FAR struct local_conn_s *) - dq_remfirst(&server->u.server.lc_waiters); + client = (FAR struct local_conn_s *) + dq_remfirst(&server->u.server.lc_waiters); - if (client) - { - /* Add the waiting connection to list of clients */ + if (client) + { + /* Add the waiting connection to list of clients */ - dq_addlast(&client->lc_node, &server->u.server.lc_conns); + dq_addlast(&client->lc_node, &server->u.server.lc_conns); - /* Decrement the number of pending clients */ + /* Decrement the number of pending clients */ - DEBUGASSERT(server->u.server.lc_pending > 0); - server->u.server.lc_pending--; + DEBUGASSERT(server->u.server.lc_pending > 0); + server->u.server.lc_pending--; - /* And signal the client that the connection was successful */ + /* And signal the client that the connection was successful */ - client->u.client.lc_result = OK; - sem_post(&client->lc_waitsem); + client->u.client.lc_result = OK; + sem_post(&client->lc_waitsem); - /* Return the address family */ + /* Return the address family */ - if (addr) - { - FAR struct sockaddr_un *unaddr; - int totlen; - int pathlen; + if (addr) + { + FAR struct sockaddr_un *unaddr; + int totlen; + int pathlen; - /* If an address is provided, then the length must also be - * provided. - */ + /* If an address is provided, then the length must also be + * provided. + */ - DEBUGASSERT(addrlen); + DEBUGASSERT(addrlen); - /* Get the length of the path (minus the NUL terminator) - * and the length of the whole client address. - */ + /* Get the length of the path (minus the NUL terminator) + * and the length of the whole client address. + */ - pathlen = strnlen(client->lc_path, UNIX_PATH_MAX-1); - totlen = sizeof(sa_family_t) + pathlen + 1; + pathlen = strnlen(client->lc_path, UNIX_PATH_MAX-1); + totlen = sizeof(sa_family_t) + pathlen + 1; - /* If the length of the whole client address is larger - * than the buffer provided by the caller, then truncate - * the address to fit. - */ + /* If the length of the whole client address is larger + * than the buffer provided by the caller, then truncate + * the address to fit. + */ - if (totlen > *addrlen) - { - pathlen -= (totlen - *addrlen); - totlen = *addrlen; - } + if (totlen > *addrlen) + { + pathlen -= (totlen - *addrlen); + totlen = *addrlen; + } - /* Copy the Unix domain address */ + /* Copy the Unix domain address */ - unaddr = (FAR struct sockaddr_un *)addr; - unaddr->sun_family = AF_LOCAL; - memcpy(unaddr->sun_path, client->lc_path, pathlen); - unaddr->sun_path[pathlen] = '\0'; + unaddr = (FAR struct sockaddr_un *)addr; + unaddr->sun_family = AF_LOCAL; + memcpy(unaddr->sun_path, client->lc_path, pathlen); + unaddr->sun_path[pathlen] = '\0'; - /* Return the Unix domain address size */ + /* Return the Unix domain address size */ - *addrlen = totlen; - } + *addrlen = totlen; + } - /* Return the client connection structure */ + /* Return the client connection structure */ - *newconn = (FAR void *)client; - return OK; - } - else - { - int ret; + *newconn = (FAR void *)client; + return OK; + } /* No.. then there should be no pending connections */ @@ -194,8 +194,6 @@ try_again: { return ret; } - - goto try_again; } } -- cgit v1.2.3