net/local: replace the listener list to global
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
b7a5b248e0
commit
1ba922a826
@ -200,12 +200,6 @@ extern "C"
|
|||||||
|
|
||||||
EXTERN const struct sock_intf_s g_local_sockif;
|
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
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -35,6 +35,14 @@
|
|||||||
|
|
||||||
#include "local/local.h"
|
#include "local/local.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* A list of all allocated packet socket connections */
|
||||||
|
|
||||||
|
static dq_queue_t g_local_connections;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -50,16 +58,14 @@
|
|||||||
|
|
||||||
void local_initialize(void)
|
void local_initialize(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_LOCAL_STREAM
|
dq_init(&g_local_connections);
|
||||||
dq_init(&g_local_listeners);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: local_nextconn
|
* Name: local_nextconn
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Traverse the list of listened local connections
|
* Traverse the list of local connections
|
||||||
*
|
*
|
||||||
* Assumptions:
|
* Assumptions:
|
||||||
* This function must be called with the network locked.
|
* 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)
|
FAR struct local_conn_s *local_nextconn(FAR struct local_conn_s *conn)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_LOCAL_STREAM
|
|
||||||
if (!conn)
|
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;
|
||||||
return (FAR struct local_conn_s *)conn->lc_node.flink;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -112,6 +112,12 @@ FAR struct local_conn_s *local_alloc(void)
|
|||||||
nxsem_init(&conn->lc_waitsem, 0, 0);
|
nxsem_init(&conn->lc_waitsem, 0, 0);
|
||||||
nxsem_set_protocol(&conn->lc_waitsem, SEM_PRIO_NONE);
|
nxsem_set_protocol(&conn->lc_waitsem, SEM_PRIO_NONE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Add the connection structure to the list of listeners */
|
||||||
|
|
||||||
|
net_lock();
|
||||||
|
dq_addlast(&conn->lc_node, &g_local_connections);
|
||||||
|
net_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
@ -130,6 +136,12 @@ void local_free(FAR struct local_conn_s *conn)
|
|||||||
{
|
{
|
||||||
DEBUGASSERT(conn != NULL);
|
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 */
|
/* Make sure that the read-only FIFO is closed */
|
||||||
|
|
||||||
if (conn->lc_infile.f_inode != NULL)
|
if (conn->lc_infile.f_inode != NULL)
|
||||||
|
@ -267,13 +267,6 @@ int psock_local_connect(FAR struct socket *psock,
|
|||||||
net_lock();
|
net_lock();
|
||||||
while ((conn = local_nextconn(conn)) != NULL)
|
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 */
|
/* Handle according to the server connection type */
|
||||||
|
|
||||||
switch (conn->lc_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 */
|
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)
|
== 0)
|
||||||
{
|
{
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
@ -36,14 +36,6 @@
|
|||||||
|
|
||||||
#include "local/local.h"
|
#include "local/local.h"
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* A list of all allocated packet socket connections */
|
|
||||||
|
|
||||||
dq_queue_t g_local_listeners;
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -118,12 +110,6 @@ int local_listen(FAR struct socket *psock, int backlog)
|
|||||||
DEBUGASSERT(server->lc_node.flink == NULL &&
|
DEBUGASSERT(server->lc_node.flink == NULL &&
|
||||||
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 */
|
/* And change the server state to listing */
|
||||||
|
|
||||||
server->lc_state = LOCAL_STATE_LISTENING;
|
server->lc_state = LOCAL_STATE_LISTENING;
|
||||||
|
@ -97,10 +97,6 @@ int local_release(FAR struct local_conn_s *conn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
conn->u.server.lc_pending = 0;
|
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 */
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user