diff --git a/net/local/local.h b/net/local/local.h index 4fe896ed77b..05b4360a85b 100644 --- a/net/local/local.h +++ b/net/local/local.h @@ -255,6 +255,19 @@ FAR struct local_conn_s *local_alloc(void); void local_free(FAR struct local_conn_s *conn); +/**************************************************************************** + * Name: local_nextconn + * + * Description: + * Traverse the list of allocated Local connections + * + * Assumptions: + * Called from network stack logic with the network stack locked + * + ****************************************************************************/ + +FAR struct local_conn_s *local_nextconn(FAR struct local_conn_s *conn); + /**************************************************************************** * Name: psock_local_bind * diff --git a/net/local/local_conn.c b/net/local/local_conn.c index 9f61bfa4593..e6e421e31e5 100644 --- a/net/local/local_conn.c +++ b/net/local/local_conn.c @@ -55,6 +55,33 @@ void local_initialize(void) #endif } +/**************************************************************************** + * Name: local_nextconn + * + * Description: + * Traverse the list of listened local connections + * + * Assumptions: + * This function must be called with the network locked. + * + ****************************************************************************/ + +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; + } + else + { + return (FAR struct local_conn_s *)conn->lc_node.flink; + } +#else + return NULL; +#endif +} + /**************************************************************************** * Name: local_alloc() * diff --git a/net/local/local_connect.c b/net/local/local_connect.c index 5618a57d598..403200fe68b 100644 --- a/net/local/local_connect.c +++ b/net/local/local_connect.c @@ -242,7 +242,7 @@ int psock_local_connect(FAR struct socket *psock, { FAR struct local_conn_s *client; FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr; - FAR struct local_conn_s *conn; + FAR struct local_conn_s *conn = NULL; DEBUGASSERT(psock && psock->s_conn); client = (FAR struct local_conn_s *)psock->s_conn; @@ -256,9 +256,7 @@ int psock_local_connect(FAR struct socket *psock, /* Find the matching server connection */ net_lock(); - for (conn = (FAR struct local_conn_s *)g_local_listeners.head; - conn; - conn = (FAR struct local_conn_s *)dq_next(&conn->lc_node)) + while ((conn = local_nextconn(conn)) != NULL) { /* Anything in the listener list should be a stream socket in the * listening state