From 202645033343cc69e0ff049948fa2dff1af54aea Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Mon, 7 Feb 2022 11:34:18 +0800 Subject: [PATCH] net/udp: replace the common connect prologue Signed-off-by: chao.an --- net/udp/udp.h | 14 ++++---------- net/udp/udp_callback.c | 2 +- net/udp/udp_conn.c | 16 ++++++++-------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/net/udp/udp.h b/net/udp/udp.h index 7665429beb..a5e779b65b 100644 --- a/net/udp/udp.h +++ b/net/udp/udp.h @@ -33,6 +33,7 @@ #include #include +#include #include #ifdef CONFIG_NET_UDP_NOTIFIER @@ -61,9 +62,9 @@ /* Allocate a new UDP data callback */ #define udp_callback_alloc(dev,conn) \ - devif_callback_alloc((dev), &(conn)->list, &(conn)->list_tail) + devif_callback_alloc((dev), &(conn)->sconn.list, &(conn)->sconn.list_tail) #define udp_callback_free(dev,conn,cb) \ - devif_conn_callback_free((dev), (cb), &(conn)->list, &(conn)->list_tail) + devif_conn_callback_free((dev), (cb), &(conn)->sconn.list, &(conn)->sconn.list_tail) /* Definitions for the UDP connection struct flag field */ @@ -99,14 +100,7 @@ struct udp_conn_s { /* Common prologue of all connection structures. */ - dq_entry_t node; /* Supports a doubly linked list */ - - /* This is a list of UDP connection callbacks. Each callback represents - * a thread that is stalled, waiting for a device-specific event. - */ - - FAR struct devif_callback_s *list; - FAR struct devif_callback_s *list_tail; + struct socket_conn_s sconn; /* UDP-specific content follows */ diff --git a/net/udp/udp_callback.c b/net/udp/udp_callback.c index 47d91f2cfb..194f8a77d8 100644 --- a/net/udp/udp_callback.c +++ b/net/udp/udp_callback.c @@ -317,7 +317,7 @@ uint16_t udp_callback(FAR struct net_driver_s *dev, { /* Perform the callback */ - flags = devif_conn_event(dev, conn, flags, conn->list); + flags = devif_conn_event(dev, conn, flags, conn->sconn.list); if ((flags & UDP_NEWDATA) != 0) { diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c index 621caac253..18f27a81f0 100644 --- a/net/udp/udp_conn.c +++ b/net/udp/udp_conn.c @@ -307,7 +307,7 @@ static inline FAR struct udp_conn_s * /* Look at the next active connection */ - conn = (FAR struct udp_conn_s *)conn->node.flink; + conn = (FAR struct udp_conn_s *)conn->sconn.node.flink; } return conn; @@ -446,7 +446,7 @@ static inline FAR struct udp_conn_s * /* Look at the next active connection */ - conn = (FAR struct udp_conn_s *)conn->node.flink; + conn = (FAR struct udp_conn_s *)conn->sconn.node.flink; } return conn; @@ -485,7 +485,7 @@ FAR struct udp_conn_s *udp_alloc_conn(void) /* Mark the connection closed and move it to the free list */ conn[i].lport = 0; - dq_addlast(&conn[i].node, &g_free_udp_connections); + dq_addlast(&conn[i].sconn.node, &g_free_udp_connections); } } @@ -594,7 +594,7 @@ void udp_initialize(void) /* Mark the connection closed and move it to the free list */ g_udp_connections[i].lport = 0; - dq_addlast(&g_udp_connections[i].node, &g_free_udp_connections); + dq_addlast(&g_udp_connections[i].sconn.node, &g_free_udp_connections); } #endif } @@ -650,7 +650,7 @@ FAR struct udp_conn_s *udp_alloc(uint8_t domain) #endif /* Enqueue the connection into the active list */ - dq_addlast(&conn->node, &g_active_udp_connections); + dq_addlast(&conn->sconn.node, &g_active_udp_connections); } _udp_semgive(&g_free_sem); @@ -681,7 +681,7 @@ void udp_free(FAR struct udp_conn_s *conn) /* Remove the connection from the active list */ - dq_rem(&conn->node, &g_active_udp_connections); + dq_rem(&conn->sconn.node, &g_active_udp_connections); /* Release any read-ahead buffers attached to the connection */ @@ -706,7 +706,7 @@ void udp_free(FAR struct udp_conn_s *conn) /* Free the connection */ - dq_addlast(&conn->node, &g_free_udp_connections); + dq_addlast(&conn->sconn.node, &g_free_udp_connections); _udp_semgive(&g_free_sem); } @@ -763,7 +763,7 @@ FAR struct udp_conn_s *udp_nextconn(FAR struct udp_conn_s *conn) } else { - return (FAR struct udp_conn_s *)conn->node.flink; + return (FAR struct udp_conn_s *)conn->sconn.node.flink; } }