You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/09/24 15:09:37 UTC

[incubator-nuttx] 03/04: net/local: add local_peerconn helper

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit ea82a0b63824e488deea57eaa745387bc87e45e1
Author: chao.an <an...@xiaomi.com>
AuthorDate: Tue Sep 14 15:21:38 2021 +0800

    net/local: add local_peerconn helper
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/local/local.h      | 13 +++++++++++++
 net/local/local_conn.c | 27 +++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/net/local/local.h b/net/local/local.h
index e65078b..c746b51 100644
--- a/net/local/local.h
+++ b/net/local/local.h
@@ -255,6 +255,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
  *
  * Description:
diff --git a/net/local/local_conn.c b/net/local/local_conn.c
index bf4faf3..3b27400 100644
--- a/net/local/local_conn.c
+++ b/net/local/local_conn.c
@@ -83,6 +83,33 @@ 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)
+{
+  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()
  *
  * Description: