mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
net/local: split the waiter node from lc_node
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
+2
-1
@@ -119,7 +119,7 @@ struct local_conn_s
|
|||||||
|
|
||||||
/* lc_node supports a doubly linked list: Listening SOCK_STREAM servers
|
/* lc_node supports a doubly linked list: Listening SOCK_STREAM servers
|
||||||
* will be linked into a list of listeners; SOCK_STREAM clients will be
|
* 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 */
|
dq_entry_t lc_node; /* Supports a doubly linked list */
|
||||||
@@ -179,6 +179,7 @@ struct local_conn_s
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
volatile int lc_result; /* Result of the connection operation (client) */
|
volatile int lc_result; /* Result of the connection operation (client) */
|
||||||
|
dq_entry_t lc_waiter; /* Linked to the lc_waiters lists */
|
||||||
} client;
|
} client;
|
||||||
} u;
|
} u;
|
||||||
#endif /* CONFIG_NET_LOCAL_STREAM */
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include <queue.h>
|
#include <queue.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/nuttx.h>
|
||||||
#include <nuttx/net/net.h>
|
#include <nuttx/net/net.h>
|
||||||
|
|
||||||
#include "socket/socket.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 *server;
|
||||||
FAR struct local_conn_s *client;
|
FAR struct local_conn_s *client;
|
||||||
FAR struct local_conn_s *conn;
|
FAR struct local_conn_s *conn;
|
||||||
|
FAR dq_entry_t *waiter;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Some sanity checks */
|
/* Some sanity checks */
|
||||||
@@ -135,11 +137,13 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
* head of the waiting list.
|
* head of the waiting list.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
client = (FAR struct local_conn_s *)
|
waiter = dq_remfirst(&server->u.server.lc_waiters);
|
||||||
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 */
|
/* Decrement the number of pending clients */
|
||||||
|
|
||||||
DEBUGASSERT(server->u.server.lc_pending > 0);
|
DEBUGASSERT(server->u.server.lc_pending > 0);
|
||||||
|
|||||||
@@ -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. */
|
/* 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);
|
local_event_pollnotify(server, POLLIN);
|
||||||
|
|
||||||
if (nxsem_get_value(&server->lc_waitsem, &sval) >= 0 && sval < 1)
|
if (nxsem_get_value(&server->lc_waitsem, &sval) >= 0 && sval < 1)
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include <queue.h>
|
#include <queue.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <nuttx/nuttx.h>
|
||||||
#include <nuttx/net/net.h>
|
#include <nuttx/net/net.h>
|
||||||
|
|
||||||
#include <arch/irq.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)
|
else if (conn->lc_state == LOCAL_STATE_LISTENING)
|
||||||
{
|
{
|
||||||
FAR struct local_conn_s *client;
|
FAR struct local_conn_s *client;
|
||||||
|
FAR dq_entry_t *waiter;
|
||||||
|
|
||||||
DEBUGASSERT(conn->lc_proto == SOCK_STREAM);
|
DEBUGASSERT(conn->lc_proto == SOCK_STREAM);
|
||||||
|
|
||||||
/* Are there still clients waiting for a connection to the server? */
|
/* Are there still clients waiting for a connection to the server? */
|
||||||
|
|
||||||
for (client =
|
for (waiter = dq_peek(&conn->u.server.lc_waiters);
|
||||||
(FAR struct local_conn_s *)conn->u.server.lc_waiters.head;
|
waiter;
|
||||||
client;
|
waiter = dq_next(&client->u.client.lc_waiter))
|
||||||
client = (FAR struct local_conn_s *)dq_next(&client->lc_node))
|
|
||||||
{
|
{
|
||||||
|
client = container_of(waiter, struct local_conn_s,
|
||||||
|
u.client.lc_waiter);
|
||||||
client->u.client.lc_result = -ENOTCONN;
|
client->u.client.lc_result = -ENOTCONN;
|
||||||
nxsem_post(&client->lc_waitsem);
|
nxsem_post(&client->lc_waitsem);
|
||||||
local_event_pollnotify(client, POLLOUT);
|
local_event_pollnotify(client, POLLOUT);
|
||||||
|
|||||||
Reference in New Issue
Block a user