net/local: add local_nextconn() helper

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2021-04-19 18:06:14 +08:00 committed by Alan Carvalho de Assis
parent 9d0da9818c
commit 805d3a2061
3 changed files with 42 additions and 4 deletions

View File

@ -255,6 +255,19 @@ FAR struct local_conn_s *local_alloc(void);
void local_free(FAR struct local_conn_s *conn);
/****************************************************************************
* Name: local_nextconn
*
* Description:
* Traverse the list of allocated Local connections
*
* Assumptions:
* Called from network stack logic with the network stack locked
*
****************************************************************************/
FAR struct local_conn_s *local_nextconn(FAR struct local_conn_s *conn);
/****************************************************************************
* Name: psock_local_bind
*

View File

@ -55,6 +55,33 @@ void local_initialize(void)
#endif
}
/****************************************************************************
* Name: local_nextconn
*
* Description:
* Traverse the list of listened local connections
*
* Assumptions:
* This function must be called with the network locked.
*
****************************************************************************/
FAR struct local_conn_s *local_nextconn(FAR struct local_conn_s *conn)
{
#ifdef CONFIG_NET_LOCAL_STREAM
if (!conn)
{
return (FAR struct local_conn_s *)g_local_listeners.head;
}
else
{
return (FAR struct local_conn_s *)conn->lc_node.flink;
}
#else
return NULL;
#endif
}
/****************************************************************************
* Name: local_alloc()
*

View File

@ -242,7 +242,7 @@ int psock_local_connect(FAR struct socket *psock,
{
FAR struct local_conn_s *client;
FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
FAR struct local_conn_s *conn;
FAR struct local_conn_s *conn = NULL;
DEBUGASSERT(psock && psock->s_conn);
client = (FAR struct local_conn_s *)psock->s_conn;
@ -256,9 +256,7 @@ int psock_local_connect(FAR struct socket *psock,
/* Find the matching server connection */
net_lock();
for (conn = (FAR struct local_conn_s *)g_local_listeners.head;
conn;
conn = (FAR struct local_conn_s *)dq_next(&conn->lc_node))
while ((conn = local_nextconn(conn)) != NULL)
{
/* Anything in the listener list should be a stream socket in the
* listening state