From d58c9f1f47708c21e22ff92e5d2d944aa47f3d9c Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Wed, 14 Jul 2021 17:30:44 +0800 Subject: [PATCH] net/wrb: add tcp/udp_inqueue_wrb_size() interface Change-Id: Iccf2829e445d4842181cd6b8c0422cdfb35c498a Signed-off-by: chao.an --- net/tcp/tcp_send_buffered.c | 38 +++++++++++++++++++++++++++++++++++ net/udp/udp_sendto_buffered.c | 32 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index a8218d7922a..fc49cb9a731 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -94,6 +94,44 @@ * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: tcp_inqueue_wrb_size + * + * Description: + * Get the in-queued write buffer size from connection + * + * Input Parameters: + * conn - The TCP connection of interest + * + * Assumptions: + * Called from user logic with the network locked. + * + ****************************************************************************/ + +static uint32_t tcp_inqueue_wrb_size(FAR struct tcp_conn_s *conn) +{ + FAR struct tcp_wrbuffer_s *wrb; + FAR sq_entry_t *entry; + uint32_t total = 0; + + if (conn) + { + for (entry = sq_peek(&conn->unacked_q); entry; entry = sq_next(entry)) + { + wrb = (FAR struct tcp_wrbuffer_s *)entry; + total += TCP_WBPKTLEN(wrb); + } + + for (entry = sq_peek(&conn->write_q); entry; entry = sq_next(entry)) + { + wrb = (FAR struct tcp_wrbuffer_s *)entry; + total += TCP_WBPKTLEN(wrb); + } + } + + return total; +} + /**************************************************************************** * Name: psock_insert_segment * diff --git a/net/udp/udp_sendto_buffered.c b/net/udp/udp_sendto_buffered.c index cefe8a30cda..899b3d5e9aa 100644 --- a/net/udp/udp_sendto_buffered.c +++ b/net/udp/udp_sendto_buffered.c @@ -105,6 +105,38 @@ static uint16_t sendto_eventhandler(FAR struct net_driver_s *dev, * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: udp_inqueue_wrb_size + * + * Description: + * Get the in-queued write buffer size from connection + * + * Input Parameters: + * conn - The UDP connection of interest + * + * Assumptions: + * Called from user logic with the network locked. + * + ****************************************************************************/ + +static uint32_t udp_inqueue_wrb_size(FAR struct udp_conn_s *conn) +{ + FAR struct udp_wrbuffer_s *wrb; + FAR sq_entry_t *entry; + uint32_t total = 0; + + if (conn) + { + for (entry = sq_peek(&conn->write_q); entry; entry = sq_next(entry)) + { + wrb = (FAR struct udp_wrbuffer_s *)entry; + total += wrb->wb_iob->io_pktlen; + } + } + + return total; +} + /**************************************************************************** * Name: sendto_writebuffer_release *