net/local: replace the listener list to global

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2021-09-13 15:06:15 +08:00 committed by Xiang Xiao
parent b7a5b248e0
commit 1ba922a826
5 changed files with 32 additions and 45 deletions

View File

@ -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
****************************************************************************/

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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 */