net/local: add local_peerconn helper

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2021-09-14 15:21:38 +08:00 committed by Xiang Xiao
parent 1e078795fb
commit ea82a0b638
2 changed files with 40 additions and 0 deletions

View File

@ -254,6 +254,19 @@ void local_free(FAR struct local_conn_s *conn);
FAR struct local_conn_s *local_nextconn(FAR struct local_conn_s *conn);
/****************************************************************************
* Name: local_peerconn
*
* Description:
* Traverse the connections list to find the peer
*
* Assumptions:
* This function must be called with the network locked.
*
****************************************************************************/
FAR struct local_conn_s *local_peerconn(FAR struct local_conn_s *conn);
/****************************************************************************
* Name: psock_local_bind
*

View File

@ -82,6 +82,33 @@ FAR struct local_conn_s *local_nextconn(FAR struct local_conn_s *conn)
return (FAR struct local_conn_s *)conn->lc_node.flink;
}
/****************************************************************************
* Name: local_peerconn
*
* Description:
* Traverse the connections list to find the peer
*
* Assumptions:
* This function must be called with the network locked.
*
****************************************************************************/
FAR struct local_conn_s *local_peerconn(FAR struct local_conn_s *conn)
{
FAR struct local_conn_s *peer = NULL;
while ((peer = local_nextconn(peer)) != NULL)
{
if (conn->lc_proto == peer->lc_proto && conn != peer &&
!strncmp(conn->lc_path, peer->lc_path, UNIX_PATH_MAX - 1))
{
return peer;
}
}
return NULL;
}
/****************************************************************************
* Name: local_alloc()
*