net: add rcvbuf socket option

Introduce set/get SO_RCVBUF option using the setsockopt
function. In addition, use the rcvbuf value to set the
tcp recv window.

Signed-off-by: Mohan Kumar Kumar <mohankm@fb.com>
This commit is contained in:
Mohan Kumar Kumar 2022-03-30 12:59:13 -07:00 committed by Carles Cufí
commit 5d37de8551
6 changed files with 98 additions and 4 deletions

View file

@ -1218,10 +1218,12 @@ static void tcp_conn_ref(struct tcp *conn)
NET_DBG("conn: %p, ref_count: %d", conn, ref_count);
}
static struct tcp *tcp_conn_alloc(void)
static struct tcp *tcp_conn_alloc(struct net_context *context)
{
struct tcp *conn = NULL;
int ret;
int recv_window = 0;
size_t len;
ret = k_mem_slab_alloc(&tcp_conns_slab, (void **)&conn, K_NO_WAIT);
if (ret) {
@ -1254,6 +1256,14 @@ static struct tcp *tcp_conn_alloc(void)
conn->state = TCP_LISTEN;
conn->recv_win = tcp_window;
/* Set the recv_win with the rcvbuf configured for the socket. */
if (IS_ENABLED(CONFIG_NET_CONTEXT_RCVBUF) &&
net_context_get_option(context, NET_OPT_RCVBUF, &recv_window, &len) == 0) {
if (recv_window != 0) {
conn->recv_win = recv_window;
}
}
/* The ISN value will be set when we get the connection attempt or
* when trying to create a connection.
*/
@ -1292,7 +1302,7 @@ int net_tcp_get(struct net_context *context)
k_mutex_lock(&tcp_lock, K_FOREVER);
conn = tcp_conn_alloc();
conn = tcp_conn_alloc(context);
if (conn == NULL) {
ret = -ENOMEM;
goto out;