Replace an un-necessary goto
This commit is contained in:
parent
f756545eb0
commit
a25f6cb7fd
@ -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 *server;
|
||||||
FAR struct local_conn_s *client;
|
FAR struct local_conn_s *client;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Some sanity checks */
|
/* Some sanity checks */
|
||||||
|
|
||||||
@ -96,84 +97,83 @@ int psock_local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Are there pending connections. Remove the client from the
|
/* Loop as necessary if we have to wait for a connection */
|
||||||
* head of the waiting list.
|
|
||||||
*/
|
|
||||||
|
|
||||||
try_again:
|
for (;;)
|
||||||
|
|
||||||
client = (FAR struct local_conn_s *)
|
|
||||||
dq_remfirst(&server->u.server.lc_waiters);
|
|
||||||
|
|
||||||
if (client)
|
|
||||||
{
|
{
|
||||||
/* Add the waiting connection to list of clients */
|
/* Are there pending connections. Remove the client from the
|
||||||
|
* head of the waiting list.
|
||||||
|
*/
|
||||||
|
|
||||||
dq_addlast(&client->lc_node, &server->u.server.lc_conns);
|
client = (FAR struct local_conn_s *)
|
||||||
|
dq_remfirst(&server->u.server.lc_waiters);
|
||||||
|
|
||||||
/* Decrement the number of pending clients */
|
if (client)
|
||||||
|
|
||||||
DEBUGASSERT(server->u.server.lc_pending > 0);
|
|
||||||
server->u.server.lc_pending--;
|
|
||||||
|
|
||||||
/* And signal the client that the connection was successful */
|
|
||||||
|
|
||||||
client->u.client.lc_result = OK;
|
|
||||||
sem_post(&client->lc_waitsem);
|
|
||||||
|
|
||||||
/* Return the address family */
|
|
||||||
|
|
||||||
if (addr)
|
|
||||||
{
|
{
|
||||||
FAR struct sockaddr_un *unaddr;
|
/* Add the waiting connection to list of clients */
|
||||||
int totlen;
|
|
||||||
int pathlen;
|
|
||||||
|
|
||||||
/* If an address is provided, then the length must also be
|
dq_addlast(&client->lc_node, &server->u.server.lc_conns);
|
||||||
* provided.
|
|
||||||
*/
|
|
||||||
|
|
||||||
DEBUGASSERT(addrlen);
|
/* Decrement the number of pending clients */
|
||||||
|
|
||||||
/* Get the length of the path (minus the NUL terminator)
|
DEBUGASSERT(server->u.server.lc_pending > 0);
|
||||||
* and the length of the whole client address.
|
server->u.server.lc_pending--;
|
||||||
*/
|
|
||||||
|
|
||||||
pathlen = strnlen(client->lc_path, UNIX_PATH_MAX-1);
|
/* And signal the client that the connection was successful */
|
||||||
totlen = sizeof(sa_family_t) + pathlen + 1;
|
|
||||||
|
|
||||||
/* If the length of the whole client address is larger
|
client->u.client.lc_result = OK;
|
||||||
* than the buffer provided by the caller, then truncate
|
sem_post(&client->lc_waitsem);
|
||||||
* the address to fit.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (totlen > *addrlen)
|
/* Return the address family */
|
||||||
|
|
||||||
|
if (addr)
|
||||||
{
|
{
|
||||||
pathlen -= (totlen - *addrlen);
|
FAR struct sockaddr_un *unaddr;
|
||||||
totlen = *addrlen;
|
int totlen;
|
||||||
|
int pathlen;
|
||||||
|
|
||||||
|
/* If an address is provided, then the length must also be
|
||||||
|
* provided.
|
||||||
|
*/
|
||||||
|
|
||||||
|
DEBUGASSERT(addrlen);
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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';
|
||||||
|
|
||||||
|
/* Return the Unix domain address size */
|
||||||
|
|
||||||
|
*addrlen = totlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the Unix domain address */
|
/* Return the client connection structure */
|
||||||
|
|
||||||
unaddr = (FAR struct sockaddr_un *)addr;
|
*newconn = (FAR void *)client;
|
||||||
unaddr->sun_family = AF_LOCAL;
|
return OK;
|
||||||
memcpy(unaddr->sun_path, client->lc_path, pathlen);
|
|
||||||
unaddr->sun_path[pathlen] = '\0';
|
|
||||||
|
|
||||||
/* Return the Unix domain address size */
|
|
||||||
|
|
||||||
*addrlen = totlen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the client connection structure */
|
|
||||||
|
|
||||||
*newconn = (FAR void *)client;
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* No.. then there should be no pending connections */
|
/* No.. then there should be no pending connections */
|
||||||
|
|
||||||
DEBUGASSERT(server->u.server.lc_pending == 0);
|
DEBUGASSERT(server->u.server.lc_pending == 0);
|
||||||
@ -194,8 +194,6 @@ try_again:
|
|||||||
{
|
{
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
goto try_again;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user