From daeeb1449cf142c707b9385954cb94cfd0c2f12c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 12 Jul 2017 20:48:21 +0300 Subject: [PATCH] net: sockets: Manage TCP receive window As we buffer incoming packets in receive callbacks, we must decrease receive window to avoid situation that incoming stream for one socket uses up all buffers in the system and causes deadlock. Once user app consumes queued data using recv() call, we increase window again. Signed-off-by: Paul Sokolovsky --- subsys/net/lib/sockets/sockets.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index 87967495a1af..5ca2d611ab45 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -141,6 +141,10 @@ static void zsock_received_cb(struct net_context *ctx, struct net_pkt *pkt, header_len = net_pkt_appdata(pkt) - pkt->frags->data; net_buf_pull(pkt->frags, header_len); + if (net_context_get_type(ctx) == SOCK_STREAM) { + net_context_update_recv_wnd(ctx, -net_pkt_appdatalen(pkt)); + } + k_fifo_put(&ctx->recv_q, pkt); } @@ -311,6 +315,8 @@ static inline ssize_t zsock_recv_stream(struct net_context *ctx, void *buf, size } } while (recv_len == 0); + net_context_update_recv_wnd(ctx, recv_len); + return recv_len; }