From 8f63596063d333c0441d0f95045e2bc62a7fc8c7 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Mon, 7 Feb 2022 11:49:41 +0800 Subject: [PATCH] net/tcp: replace the common connect prologue Signed-off-by: chao.an --- net/tcp/tcp.h | 10 ++++------ net/tcp/tcp_callback.c | 2 +- net/tcp/tcp_conn.c | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index c4cbf5d68c..867c6711ad 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -34,6 +34,7 @@ #include #include #include +#include #ifdef CONFIG_NET_TCP_NOTIFIER # include @@ -54,9 +55,9 @@ */ #define tcp_callback_alloc(conn) \ - devif_callback_alloc((conn)->dev, &(conn)->list, &(conn)->list_tail) + devif_callback_alloc((conn)->dev, &(conn)->sconn.list, &(conn)->sconn.list_tail) #define tcp_callback_free(conn,cb) \ - devif_conn_callback_free((conn)->dev, (cb), &(conn)->list, &(conn)->list_tail) + devif_conn_callback_free((conn)->dev, (cb), &(conn)->sconn.list, &(conn)->sconn.list_tail) #ifdef CONFIG_NET_TCP_WRITE_BUFFERS /* TCP write buffer access macros */ @@ -145,8 +146,6 @@ struct tcp_conn_s { /* Common prologue of all connection structures. */ - dq_entry_t node; /* Implements a doubly linked list */ - /* TCP callbacks: * * Data transfer events are retained in 'list'. Event handlers in 'list' @@ -171,8 +170,7 @@ struct tcp_conn_s * then dev->d_len should also be cleared). */ - FAR struct devif_callback_s *list; - FAR struct devif_callback_s *list_tail; + struct socket_conn_s sconn; /* TCP-specific content follows */ diff --git a/net/tcp/tcp_callback.c b/net/tcp/tcp_callback.c index 4bf6e43bb3..a76bd20fb4 100644 --- a/net/tcp/tcp_callback.c +++ b/net/tcp/tcp_callback.c @@ -166,7 +166,7 @@ uint16_t tcp_callback(FAR struct net_driver_s *dev, * not set, then dev->d_len should also be cleared). */ - flags = devif_conn_event(dev, conn, flags, conn->list); + flags = devif_conn_event(dev, conn, flags, conn->sconn.list); /* There may be no new data handler in place at them moment that the new * incoming data is received. If the new incoming data was not handled, diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index f2413a1fc2..adf0a1e36a 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -317,7 +317,7 @@ static inline FAR struct tcp_conn_s * /* Look at the next active connection */ - conn = (FAR struct tcp_conn_s *)conn->node.flink; + conn = (FAR struct tcp_conn_s *)conn->sconn.node.flink; } return conn; @@ -384,7 +384,7 @@ static inline FAR struct tcp_conn_s * /* Look at the next active connection */ - conn = (FAR struct tcp_conn_s *)conn->node.flink; + conn = (FAR struct tcp_conn_s *)conn->sconn.node.flink; } return conn; @@ -555,7 +555,7 @@ FAR struct tcp_conn_s *tcp_alloc_conn(void) /* Mark the connection closed and move it to the free list */ conn[i].tcpstateflags = TCP_CLOSED; - dq_addlast(&conn[i].node, &g_free_tcp_connections); + dq_addlast(&conn[i].sconn.node, &g_free_tcp_connections); } } @@ -595,7 +595,7 @@ void tcp_initialize(void) /* Mark the connection closed and move it to the free list */ g_tcp_connections[i].tcpstateflags = TCP_CLOSED; - dq_addlast(&g_tcp_connections[i].node, &g_free_tcp_connections); + dq_addlast(&g_tcp_connections[i].sconn.node, &g_free_tcp_connections); } #endif } @@ -668,7 +668,7 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain) /* Look at the next active connection */ - tmp = (FAR struct tcp_conn_s *)tmp->node.flink; + tmp = (FAR struct tcp_conn_s *)tmp->sconn.node.flink; } /* Did we find a connection that we can re-use? */ @@ -769,7 +769,7 @@ void tcp_free(FAR struct tcp_conn_s *conn) * callback for CONFIG_NET_TCP_WRITE_BUFFERS is left. */ - for (cb = conn->list; cb; cb = next) + for (cb = conn->sconn.list; cb; cb = next) { next = cb->nxtconn; tcp_callback_free(conn, cb); @@ -783,7 +783,7 @@ void tcp_free(FAR struct tcp_conn_s *conn) { /* Remove the connection from the active list */ - dq_rem(&conn->node, &g_active_tcp_connections); + dq_rem(&conn->sconn.node, &g_active_tcp_connections); } /* Release any read-ahead buffers attached to the connection */ @@ -835,7 +835,7 @@ void tcp_free(FAR struct tcp_conn_s *conn) /* Mark the connection available and put it into the free list */ conn->tcpstateflags = TCP_CLOSED; - dq_addlast(&conn->node, &g_free_tcp_connections); + dq_addlast(&conn->sconn.node, &g_free_tcp_connections); net_unlock(); } @@ -892,7 +892,7 @@ FAR struct tcp_conn_s *tcp_nextconn(FAR struct tcp_conn_s *conn) } else { - return (FAR struct tcp_conn_s *)conn->node.flink; + return (FAR struct tcp_conn_s *)conn->sconn.node.flink; } } @@ -1053,7 +1053,7 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, * Interrupts should already be disabled in this context. */ - dq_addlast(&conn->node, &g_active_tcp_connections); + dq_addlast(&conn->sconn.node, &g_active_tcp_connections); } return conn; @@ -1325,7 +1325,7 @@ int tcp_connect(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr) /* And, finally, put the connection structure into the active list. */ - dq_addlast(&conn->node, &g_active_tcp_connections); + dq_addlast(&conn->sconn.node, &g_active_tcp_connections); ret = OK; errout_with_lock: