summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-01-25 17:53:01 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-01-25 17:53:01 -0600
commitb3a86b681e90f212a78ab8ed0991c5f991fd030e (patch)
treea49ecc4b9206bf2fed749e862a2840b6318ac6c4
parent8cac18f0f8619c9f3f0a6429904eeceb3c965302 (diff)
downloadnuttx-b3a86b681e90f212a78ab8ed0991c5f991fd030e.tar.gz
nuttx-b3a86b681e90f212a78ab8ed0991c5f991fd030e.tar.bz2
nuttx-b3a86b681e90f212a78ab8ed0991c5f991fd030e.zip
Replace an un-necessary goto
-rw-r--r--nuttx/net/local/local_accept.c112
1 files 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;
}
}