net/icmp: replace the common connect prologue
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
f7bf28deac
commit
1f4de9e13c
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include <nuttx/mm/iob.h>
|
#include <nuttx/mm/iob.h>
|
||||||
#include <nuttx/net/ip.h>
|
#include <nuttx/net/ip.h>
|
||||||
|
#include <nuttx/net/net.h>
|
||||||
#include <nuttx/net/netdev.h>
|
#include <nuttx/net/netdev.h>
|
||||||
|
|
||||||
#if defined(CONFIG_NET_ICMP) && !defined(CONFIG_NET_ICMP_NO_STACK)
|
#if defined(CONFIG_NET_ICMP) && !defined(CONFIG_NET_ICMP_NO_STACK)
|
||||||
@ -47,9 +48,9 @@
|
|||||||
/* Allocate/free an ICMP data callback */
|
/* Allocate/free an ICMP data callback */
|
||||||
|
|
||||||
#define icmp_callback_alloc(dev, conn) \
|
#define icmp_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 icmp_callback_free(dev, conn, cb) \
|
#define icmp_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)
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public types
|
* Public types
|
||||||
@ -77,14 +78,7 @@ struct icmp_conn_s
|
|||||||
{
|
{
|
||||||
/* Common prologue of all connection structures. */
|
/* Common prologue of all connection structures. */
|
||||||
|
|
||||||
dq_entry_t node; /* Supports a doubly linked list */
|
struct socket_conn_s sconn;
|
||||||
|
|
||||||
/* This is a list of ICMP 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;
|
|
||||||
|
|
||||||
/* ICMP-specific content follows */
|
/* ICMP-specific content follows */
|
||||||
|
|
||||||
|
@ -91,7 +91,8 @@ void icmp_sock_initialize(void)
|
|||||||
{
|
{
|
||||||
/* Move the connection structure to the free list */
|
/* Move the connection structure to the free list */
|
||||||
|
|
||||||
dq_addlast(&g_icmp_connections[i].node, &g_free_icmp_connections);
|
dq_addlast(&g_icmp_connections[i].sconn.node,
|
||||||
|
&g_free_icmp_connections);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -124,7 +125,8 @@ FAR struct icmp_conn_s *icmp_alloc(void)
|
|||||||
{
|
{
|
||||||
for (ret = 0; ret < CONFIG_NET_ICMP_NCONNS; ret++)
|
for (ret = 0; ret < CONFIG_NET_ICMP_NCONNS; ret++)
|
||||||
{
|
{
|
||||||
dq_addlast(&conn[ret].node, &g_free_icmp_connections);
|
dq_addlast(&conn[ret].sconn.node,
|
||||||
|
&g_free_icmp_connections);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +137,7 @@ FAR struct icmp_conn_s *icmp_alloc(void)
|
|||||||
{
|
{
|
||||||
/* Enqueue the connection into the active list */
|
/* Enqueue the connection into the active list */
|
||||||
|
|
||||||
dq_addlast(&conn->node, &g_active_icmp_connections);
|
dq_addlast(&conn->sconn.node, &g_active_icmp_connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
nxsem_post(&g_free_sem);
|
nxsem_post(&g_free_sem);
|
||||||
@ -177,7 +179,7 @@ void icmp_free(FAR struct icmp_conn_s *conn)
|
|||||||
{
|
{
|
||||||
/* Remove the connection from the active list */
|
/* Remove the connection from the active list */
|
||||||
|
|
||||||
dq_rem(&conn->node, &g_active_icmp_connections);
|
dq_rem(&conn->sconn.node, &g_active_icmp_connections);
|
||||||
|
|
||||||
/* Clear the connection structure */
|
/* Clear the connection structure */
|
||||||
|
|
||||||
@ -185,7 +187,7 @@ void icmp_free(FAR struct icmp_conn_s *conn)
|
|||||||
|
|
||||||
/* Free the connection */
|
/* Free the connection */
|
||||||
|
|
||||||
dq_addlast(&conn->node, &g_free_icmp_connections);
|
dq_addlast(&conn->sconn.node, &g_free_icmp_connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
nxsem_post(&g_free_sem);
|
nxsem_post(&g_free_sem);
|
||||||
@ -221,7 +223,7 @@ FAR struct icmp_conn_s *icmp_active(uint16_t id)
|
|||||||
|
|
||||||
/* Look at the next active connection */
|
/* Look at the next active connection */
|
||||||
|
|
||||||
conn = (FAR struct icmp_conn_s *)conn->node.flink;
|
conn = (FAR struct icmp_conn_s *)conn->sconn.node.flink;
|
||||||
}
|
}
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
@ -246,7 +248,7 @@ FAR struct icmp_conn_s *icmp_nextconn(FAR struct icmp_conn_s *conn)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (FAR struct icmp_conn_s *)conn->node.flink;
|
return (FAR struct icmp_conn_s *)conn->sconn.node.flink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ void icmp_input(FAR struct net_driver_s *dev)
|
|||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = devif_conn_event(dev, conn, ICMP_NEWDATA, conn->list);
|
flags = devif_conn_event(dev, conn, ICMP_NEWDATA, conn->sconn.list);
|
||||||
if ((flags & ICMP_NEWDATA) != 0)
|
if ((flags & ICMP_NEWDATA) != 0)
|
||||||
{
|
{
|
||||||
uint16_t nbuffered;
|
uint16_t nbuffered;
|
||||||
|
@ -72,7 +72,7 @@ void icmp_poll(FAR struct net_driver_s *dev, FAR struct icmp_conn_s *conn)
|
|||||||
|
|
||||||
/* Perform the application callback */
|
/* Perform the application callback */
|
||||||
|
|
||||||
devif_conn_event(dev, conn, ICMP_POLL, conn->list);
|
devif_conn_event(dev, conn, ICMP_POLL, conn->sconn.list);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NET_ICMP && CONFIG_NET_ICMP_SOCKET */
|
#endif /* CONFIG_NET && CONFIG_NET_ICMP && CONFIG_NET_ICMP_SOCKET */
|
||||||
|
Loading…
Reference in New Issue
Block a user