net/local: split the waiter node from lc_node

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2021-09-16 13:40:02 +08:00 committed by Xiang Xiao
parent 1ba922a826
commit 1e078795fb
4 changed files with 17 additions and 9 deletions

View File

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

View File

@ -31,6 +31,7 @@
#include <queue.h>
#include <debug.h>
#include <nuttx/nuttx.h>
#include <nuttx/net/net.h>
#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);

View File

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

View File

@ -29,6 +29,7 @@
#include <queue.h>
#include <assert.h>
#include <nuttx/nuttx.h>
#include <nuttx/net/net.h>
#include <arch/irq.h>
@ -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);