You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/09/24 15:09:36 UTC
[incubator-nuttx] 02/04: net/local: split the waiter node from
lc_node
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 1e078795fb6d4d6c743a906648b8df78f032c289
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu Sep 16 13:40:02 2021 +0800
net/local: split the waiter node from lc_node
Signed-off-by: chao.an <an...@xiaomi.com>
---
net/local/local.h | 3 ++-
net/local/local_accept.c | 10 +++++++---
net/local/local_connect.c | 2 +-
net/local/local_release.c | 11 +++++++----
4 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/net/local/local.h b/net/local/local.h
index 3088e1f..e65078b 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 53a3ab2..4529dab 100644
--- a/net/local/local_accept.c
+++ b/net/local/local_accept.c
@@ -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);
diff --git a/net/local/local_connect.c b/net/local/local_connect.c
index 6dda5c5..b3aff31 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 dbbd796..7b10671 100644
--- a/net/local/local_release.c
+++ b/net/local/local_release.c
@@ -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);