net/local: add local_peerconn helper

Change-Id: I2cbceb68f709c581bc0b878844dd16efcd76d4a7
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 anchao
parent 0b1f2fcb45
commit 09a752e602
2 changed files with 40 additions and 0 deletions
+13
View File
@@ -259,6 +259,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
*
+27
View File
@@ -82,6 +82,33 @@ FAR struct local_conn_s *local_nextconn(FAR struct local_conn_s *conn)
#endif
}
/****************************************************************************
* 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()
*