diff --git a/net/local/local.h b/net/local/local.h index 3088e1ff9a..e65078b46c 100644 --- a/net/local/local.h +++ b/net/local/local.h @@ -119,7 +119,7 @@ struct local_conn_s /* lc_node supports a doubly linked list: Listening SOCK_STREAM servers * will be linked into a list of listeners; SOCK_STREAM clients will be - * linked to the lc_waiters and lc_conn lists. + * linked to the lc_conn lists. */ dq_entry_t lc_node; /* Supports a doubly linked list */ @@ -179,6 +179,7 @@ struct local_conn_s struct { volatile int lc_result; /* Result of the connection operation (client) */ + dq_entry_t lc_waiter; /* Linked to the lc_waiters lists */ } client; } u; #endif /* CONFIG_NET_LOCAL_STREAM */ diff --git a/net/local/local_accept.c b/net/local/local_accept.c index 53a3ab2414..4529dabb15 100644 --- a/net/local/local_accept.c +++ b/net/local/local_accept.c @@ -31,6 +31,7 @@ #include #include +#include #include #include "socket/socket.h" @@ -100,6 +101,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, FAR struct local_conn_s *server; FAR struct local_conn_s *client; FAR struct local_conn_s *conn; + FAR dq_entry_t *waiter; int ret; /* Some sanity checks */ @@ -135,11 +137,13 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, * head of the waiting list. */ - client = (FAR struct local_conn_s *) - dq_remfirst(&server->u.server.lc_waiters); + waiter = dq_remfirst(&server->u.server.lc_waiters); - if (client) + if (waiter) { + client = container_of(waiter, struct local_conn_s, + u.client.lc_waiter); + /* Decrement the number of pending clients */ DEBUGASSERT(server->u.server.lc_pending > 0); diff --git a/net/local/local_connect.c b/net/local/local_connect.c index 6dda5c57a3..b3aff310a1 100644 --- a/net/local/local_connect.c +++ b/net/local/local_connect.c @@ -138,7 +138,7 @@ static int inline local_stream_connect(FAR struct local_conn_s *client, /* Add ourself to the list of waiting connections and notify the server. */ - dq_addlast(&client->lc_node, &server->u.server.lc_waiters); + dq_addlast(&client->u.client.lc_waiter, &server->u.server.lc_waiters); local_event_pollnotify(server, POLLIN); if (nxsem_get_value(&server->lc_waitsem, &sval) >= 0 && sval < 1) diff --git a/net/local/local_release.c b/net/local/local_release.c index dbbd796742..7b10671ac1 100644 --- a/net/local/local_release.c +++ b/net/local/local_release.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -81,16 +82,18 @@ int local_release(FAR struct local_conn_s *conn) else if (conn->lc_state == LOCAL_STATE_LISTENING) { FAR struct local_conn_s *client; + FAR dq_entry_t *waiter; DEBUGASSERT(conn->lc_proto == SOCK_STREAM); /* Are there still clients waiting for a connection to the server? */ - for (client = - (FAR struct local_conn_s *)conn->u.server.lc_waiters.head; - client; - client = (FAR struct local_conn_s *)dq_next(&client->lc_node)) + for (waiter = dq_peek(&conn->u.server.lc_waiters); + waiter; + waiter = dq_next(&client->u.client.lc_waiter)) { + client = container_of(waiter, struct local_conn_s, + u.client.lc_waiter); client->u.client.lc_result = -ENOTCONN; nxsem_post(&client->lc_waitsem); local_event_pollnotify(client, POLLOUT);