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:35 UTC
[incubator-nuttx] 01/04: net/local: replace the listener list to
global
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 1ba922a826b753288617c0843e550db111a00db2
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Sep 13 15:06:15 2021 +0800
net/local: replace the listener list to global
Signed-off-by: chao.an <an...@xiaomi.com>
---
net/local/local.h | 6 ------
net/local/local_conn.c | 38 +++++++++++++++++++++++++-------------
net/local/local_connect.c | 15 +++++++--------
net/local/local_listen.c | 14 --------------
net/local/local_release.c | 4 ----
5 files changed, 32 insertions(+), 45 deletions(-)
diff --git a/net/local/local.h b/net/local/local.h
index bc60487..3088e1f 100644
--- a/net/local/local.h
+++ b/net/local/local.h
@@ -200,12 +200,6 @@ extern "C"
EXTERN const struct sock_intf_s g_local_sockif;
-#ifdef CONFIG_NET_LOCAL_STREAM
-/* A list of all SOCK_STREAM listener connections */
-
-EXTERN dq_queue_t g_local_listeners;
-#endif
-
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
diff --git a/net/local/local_conn.c b/net/local/local_conn.c
index e6e421e..bf4faf3 100644
--- a/net/local/local_conn.c
+++ b/net/local/local_conn.c
@@ -36,6 +36,14 @@
#include "local/local.h"
/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* A list of all allocated packet socket connections */
+
+static dq_queue_t g_local_connections;
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -50,16 +58,14 @@
void local_initialize(void)
{
-#ifdef CONFIG_NET_LOCAL_STREAM
- dq_init(&g_local_listeners);
-#endif
+ dq_init(&g_local_connections);
}
/****************************************************************************
* Name: local_nextconn
*
* Description:
- * Traverse the list of listened local connections
+ * Traverse the list of local connections
*
* Assumptions:
* This function must be called with the network locked.
@@ -68,18 +74,12 @@ void local_initialize(void)
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;
+ return (FAR struct local_conn_s *)g_local_connections.head;
}
- else
- {
- return (FAR struct local_conn_s *)conn->lc_node.flink;
- }
-#else
- return NULL;
-#endif
+
+ return (FAR struct local_conn_s *)conn->lc_node.flink;
}
/****************************************************************************
@@ -112,6 +112,12 @@ FAR struct local_conn_s *local_alloc(void)
nxsem_init(&conn->lc_waitsem, 0, 0);
nxsem_set_protocol(&conn->lc_waitsem, SEM_PRIO_NONE);
#endif
+
+ /* Add the connection structure to the list of listeners */
+
+ net_lock();
+ dq_addlast(&conn->lc_node, &g_local_connections);
+ net_unlock();
}
return conn;
@@ -130,6 +136,12 @@ void local_free(FAR struct local_conn_s *conn)
{
DEBUGASSERT(conn != NULL);
+ /* Remove the server from the list of listeners. */
+
+ net_lock();
+ dq_rem(&conn->lc_node, &g_local_connections);
+ net_unlock();
+
/* Make sure that the read-only FIFO is closed */
if (conn->lc_infile.f_inode != NULL)
diff --git a/net/local/local_connect.c b/net/local/local_connect.c
index 5bcf426..6dda5c5 100644
--- a/net/local/local_connect.c
+++ b/net/local/local_connect.c
@@ -267,13 +267,6 @@ int psock_local_connect(FAR struct socket *psock,
net_lock();
while ((conn = local_nextconn(conn)) != NULL)
{
- /* Anything in the listener list should be a stream socket in the
- * listening state
- */
-
- DEBUGASSERT(conn->lc_state == LOCAL_STATE_LISTENING &&
- conn->lc_proto == SOCK_STREAM);
-
/* Handle according to the server connection type */
switch (conn->lc_type)
@@ -289,7 +282,13 @@ int psock_local_connect(FAR struct socket *psock,
case LOCAL_TYPE_PATHNAME: /* lc_path holds a null terminated string */
{
- if (strncmp(conn->lc_path, unaddr->sun_path, UNIX_PATH_MAX - 1)
+ /* Anything in the listener list should be a stream socket in the
+ * listening state
+ */
+
+ if (conn->lc_state == LOCAL_STATE_LISTENING &&
+ conn->lc_proto == SOCK_STREAM &&
+ strncmp(conn->lc_path, unaddr->sun_path, UNIX_PATH_MAX - 1)
== 0)
{
int ret = OK;
diff --git a/net/local/local_listen.c b/net/local/local_listen.c
index f3d3271..a69ca1d 100644
--- a/net/local/local_listen.c
+++ b/net/local/local_listen.c
@@ -37,14 +37,6 @@
#include "local/local.h"
/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/* A list of all allocated packet socket connections */
-
-dq_queue_t g_local_listeners;
-
-/****************************************************************************
* Public Functions
****************************************************************************/
@@ -118,12 +110,6 @@ int local_listen(FAR struct socket *psock, int backlog)
DEBUGASSERT(server->lc_node.flink == NULL &&
server->lc_node.flink == NULL);
- /* Add the connection structure to the list of listeners */
-
- net_lock();
- dq_addlast(&server->lc_node, &g_local_listeners);
- net_unlock();
-
/* And change the server state to listing */
server->lc_state = LOCAL_STATE_LISTENING;
diff --git a/net/local/local_release.c b/net/local/local_release.c
index 22a81d4..dbbd796 100644
--- a/net/local/local_release.c
+++ b/net/local/local_release.c
@@ -97,10 +97,6 @@ int local_release(FAR struct local_conn_s *conn)
}
conn->u.server.lc_pending = 0;
-
- /* Remove the server from the list of listeners. */
-
- dq_rem(&conn->lc_node, &g_local_listeners);
}
#endif /* CONFIG_NET_LOCAL_STREAM */