diff --git a/net/local/local.h b/net/local/local.h index bc604872ee..3088e1ff9a 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 e6e421e31e..bf4faf32d0 100644 --- a/net/local/local_conn.c +++ b/net/local/local_conn.c @@ -35,6 +35,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 5bcf42674c..6dda5c57a3 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 f3d3271a83..a69ca1d309 100644 --- a/net/local/local_listen.c +++ b/net/local/local_listen.c @@ -36,14 +36,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 22a81d4a40..dbbd796742 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 */