net/udp: replace the common connect prologue

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2022-02-07 11:34:18 +08:00 committed by Alan Carvalho de Assis
parent 1f4de9e13c
commit 2026450333
3 changed files with 13 additions and 19 deletions

View File

@ -33,6 +33,7 @@
#include <nuttx/semaphore.h>
#include <nuttx/net/ip.h>
#include <nuttx/net/net.h>
#include <nuttx/mm/iob.h>
#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 */

View File

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

View File

@ -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;
}
}