net/tcp/udp: move the send callback into tcp/udp structure
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
cfee589a4a
commit
39e142243d
@ -264,13 +264,6 @@ struct socket
|
||||
/* Socket interface */
|
||||
|
||||
FAR const struct sock_intf_s *s_sockif;
|
||||
|
||||
#if defined(CONFIG_NET_TCP_WRITE_BUFFERS) || \
|
||||
defined(CONFIG_NET_UDP_WRITE_BUFFERS)
|
||||
/* Callback instance for TCP send() or UDP sendto() */
|
||||
|
||||
FAR struct devif_callback_s *s_sndcb;
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -87,9 +87,6 @@ int psock_socket(int domain, int type, int protocol,
|
||||
psock->s_domain = domain;
|
||||
psock->s_proto = protocol;
|
||||
psock->s_conn = NULL;
|
||||
#if defined(CONFIG_NET_TCP_WRITE_BUFFERS) || defined(CONFIG_NET_UDP_WRITE_BUFFERS)
|
||||
psock->s_sndcb = NULL;
|
||||
#endif
|
||||
|
||||
if (type & SOCK_NONBLOCK)
|
||||
{
|
||||
|
@ -309,6 +309,12 @@ struct tcp_conn_s
|
||||
FAR struct devif_callback_s *connevents;
|
||||
FAR struct devif_callback_s *connevents_tail;
|
||||
|
||||
#if defined(CONFIG_NET_TCP_WRITE_BUFFERS)
|
||||
/* Callback instance for TCP send() */
|
||||
|
||||
FAR struct devif_callback_s *sndcb;
|
||||
#endif
|
||||
|
||||
/* accept() is called when the TCP logic has created a connection
|
||||
*
|
||||
* accept_private: This is private data that will be available to the
|
||||
|
@ -161,18 +161,16 @@ static uint16_t tcp_close_eventhandler(FAR struct net_driver_s *dev,
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
|
||||
FAR struct socket *psock = pstate->cl_psock;
|
||||
|
||||
/* We don't need the send callback anymore. */
|
||||
|
||||
if (psock->s_sndcb != NULL)
|
||||
if (conn->sndcb != NULL)
|
||||
{
|
||||
psock->s_sndcb->flags = 0;
|
||||
psock->s_sndcb->event = NULL;
|
||||
conn->sndcb->flags = 0;
|
||||
conn->sndcb->event = NULL;
|
||||
|
||||
/* The callback will be freed by tcp_free. */
|
||||
|
||||
psock->s_sndcb = NULL;
|
||||
conn->sndcb = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -238,10 +238,10 @@ static inline void psock_lost_connection(FAR struct socket *psock,
|
||||
|
||||
/* Do not allow any further callbacks */
|
||||
|
||||
if (psock->s_sndcb != NULL)
|
||||
if (conn->sndcb != NULL)
|
||||
{
|
||||
psock->s_sndcb->flags = 0;
|
||||
psock->s_sndcb->event = NULL;
|
||||
conn->sndcb->flags = 0;
|
||||
conn->sndcb->event = NULL;
|
||||
}
|
||||
|
||||
if (conn != NULL)
|
||||
@ -414,7 +414,7 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
|
||||
{
|
||||
/* Report not connected */
|
||||
|
||||
tcp_lost_connection(psock, psock->s_sndcb, flags);
|
||||
tcp_lost_connection(psock, conn->sndcb, flags);
|
||||
}
|
||||
|
||||
/* Free write buffers and terminate polling */
|
||||
@ -1142,14 +1142,14 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
||||
|
||||
/* Allocate resources to receive a callback */
|
||||
|
||||
if (psock->s_sndcb == NULL)
|
||||
if (conn->sndcb == NULL)
|
||||
{
|
||||
psock->s_sndcb = tcp_callback_alloc(conn);
|
||||
conn->sndcb = tcp_callback_alloc(conn);
|
||||
}
|
||||
|
||||
/* Test if the callback has been allocated */
|
||||
|
||||
if (psock->s_sndcb == NULL)
|
||||
if (conn->sndcb == NULL)
|
||||
{
|
||||
/* A buffer allocation error occurred */
|
||||
|
||||
@ -1160,10 +1160,10 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
||||
|
||||
/* Set up the callback in the connection */
|
||||
|
||||
psock->s_sndcb->flags = (TCP_ACKDATA | TCP_REXMIT | TCP_POLL |
|
||||
conn->sndcb->flags = (TCP_ACKDATA | TCP_REXMIT | TCP_POLL |
|
||||
TCP_DISCONN_EVENTS);
|
||||
psock->s_sndcb->priv = (FAR void *)psock;
|
||||
psock->s_sndcb->event = psock_send_eventhandler;
|
||||
conn->sndcb->priv = (FAR void *)psock;
|
||||
conn->sndcb->event = psock_send_eventhandler;
|
||||
|
||||
#if CONFIG_NET_SEND_BUFSIZE > 0
|
||||
/* If the send buffer size exceeds the send limit,
|
||||
|
@ -147,6 +147,10 @@ struct udp_conn_s
|
||||
|
||||
sq_queue_t write_q; /* Write buffering for UDP packets */
|
||||
FAR struct net_driver_s *dev; /* Last device */
|
||||
|
||||
/* Callback instance for UDP sendto() */
|
||||
|
||||
FAR struct devif_callback_s *sndcb;
|
||||
#endif
|
||||
|
||||
/* The following is a list of poll structures of threads waiting for
|
||||
|
@ -131,10 +131,10 @@ int udp_close(FAR struct socket *psock)
|
||||
#ifdef CONFIG_NET_UDP_WRITE_BUFFERS
|
||||
/* Free any semi-permanent write buffer callback in place. */
|
||||
|
||||
if (psock->s_sndcb != NULL)
|
||||
if (conn->sndcb != NULL)
|
||||
{
|
||||
udp_callback_free(conn->dev, conn, psock->s_sndcb);
|
||||
psock->s_sndcb = NULL;
|
||||
udp_callback_free(conn->dev, conn, conn->sndcb);
|
||||
conn->sndcb = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -173,9 +173,9 @@ static void sendto_writebuffer_release(FAR struct socket *psock,
|
||||
* enqueued.
|
||||
*/
|
||||
|
||||
psock->s_sndcb->flags = 0;
|
||||
psock->s_sndcb->priv = NULL;
|
||||
psock->s_sndcb->event = NULL;
|
||||
conn->sndcb->flags = 0;
|
||||
conn->sndcb->priv = NULL;
|
||||
conn->sndcb->event = NULL;
|
||||
wrb = NULL;
|
||||
|
||||
#ifdef CONFIG_NET_UDP_NOTIFIER
|
||||
@ -331,24 +331,24 @@ static int sendto_next_transfer(FAR struct socket *psock,
|
||||
* callback instance.
|
||||
*/
|
||||
|
||||
if (psock->s_sndcb != NULL && conn->dev != dev)
|
||||
if (conn->sndcb != NULL && conn->dev != dev)
|
||||
{
|
||||
udp_callback_free(conn->dev, conn, psock->s_sndcb);
|
||||
psock->s_sndcb = NULL;
|
||||
udp_callback_free(conn->dev, conn, conn->sndcb);
|
||||
conn->sndcb = NULL;
|
||||
}
|
||||
|
||||
/* Allocate resources to receive a callback from this device if the
|
||||
* callback is not already in place.
|
||||
*/
|
||||
|
||||
if (psock->s_sndcb == NULL)
|
||||
if (conn->sndcb == NULL)
|
||||
{
|
||||
psock->s_sndcb = udp_callback_alloc(dev, conn);
|
||||
conn->sndcb = udp_callback_alloc(dev, conn);
|
||||
}
|
||||
|
||||
/* Test if the callback has been allocated */
|
||||
|
||||
if (psock->s_sndcb == NULL)
|
||||
if (conn->sndcb == NULL)
|
||||
{
|
||||
/* A buffer allocation error occurred */
|
||||
|
||||
@ -360,9 +360,9 @@ static int sendto_next_transfer(FAR struct socket *psock,
|
||||
|
||||
/* Set up the callback in the connection */
|
||||
|
||||
psock->s_sndcb->flags = (UDP_POLL | NETDEV_DOWN);
|
||||
psock->s_sndcb->priv = (FAR void *)psock;
|
||||
psock->s_sndcb->event = sendto_eventhandler;
|
||||
conn->sndcb->flags = (UDP_POLL | NETDEV_DOWN);
|
||||
conn->sndcb->priv = (FAR void *)psock;
|
||||
conn->sndcb->event = sendto_eventhandler;
|
||||
|
||||
/* Notify the device driver of the availability of TX data */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user