net: tcp/udp/icmp/icmpv6 add FIONSPACE support

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2022-03-31 11:40:08 +08:00
committed by Xiang Xiao
parent 931a64717a
commit c50d7e174f
16 changed files with 362 additions and 80 deletions
+18
View File
@@ -1617,6 +1617,24 @@ FAR struct tcp_wrbuffer_s *tcp_wrbuffer_tryalloc(void);
void tcp_wrbuffer_release(FAR struct tcp_wrbuffer_s *wrb);
#endif /* CONFIG_NET_TCP_WRITE_BUFFERS */
/****************************************************************************
* Name: tcp_wrbuffer_inqueue_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.
*
****************************************************************************/
#if CONFIG_NET_SEND_BUFSIZE > 0
uint32_t tcp_wrbuffer_inqueue_size(FAR struct tcp_conn_s *conn);
#endif
/****************************************************************************
* Name: tcp_wrbuffer_test
*
+13
View File
@@ -74,6 +74,19 @@ int tcp_ioctl(FAR struct tcp_conn_s *conn,
*(FAR int *)((uintptr_t)arg) = 0;
}
break;
case FIONSPACE:
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
# if CONFIG_NET_SEND_BUFSIZE == 0
*(FAR int *)((uintptr_t)arg) =
iob_navail(true) * CONFIG_IOB_BUFSIZE;
# else
*(FAR int *)((uintptr_t)arg) =
conn->snd_bufs - tcp_wrbuffer_inqueue_size(conn);
# endif
#else
*(FAR int *)((uintptr_t)arg) = MIN_TCP_MSS;
#endif
break;
default:
ret = -ENOTTY;
break;
+1 -41
View File
@@ -94,46 +94,6 @@
* 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.
*
****************************************************************************/
#if CONFIG_NET_SEND_BUFSIZE > 0
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;
}
#endif /* CONFIG_NET_SEND_BUFSIZE */
/****************************************************************************
* Name: psock_insert_segment
*
@@ -1223,7 +1183,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
* wait for the write buffer to be released
*/
while (tcp_inqueue_wrb_size(conn) >= conn->snd_bufs)
while (tcp_wrbuffer_inqueue_size(conn) >= conn->snd_bufs)
{
if (nonblock)
{
+40
View File
@@ -249,6 +249,46 @@ void tcp_wrbuffer_release(FAR struct tcp_wrbuffer_s *wrb)
nxsem_post(&g_wrbuffer.sem);
}
/****************************************************************************
* Name: tcp_wrbuffer_inqueue_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.
*
****************************************************************************/
#if CONFIG_NET_SEND_BUFSIZE > 0
uint32_t tcp_wrbuffer_inqueue_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;
}
#endif /* CONFIG_NET_SEND_BUFSIZE */
/****************************************************************************
* Name: tcp_wrbuffer_test
*