Skip to content

Commit

Permalink
net: sockets: Manage TCP receive window
Browse files Browse the repository at this point in the history
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 <paul.sokolovsky@linaro.org>
  • Loading branch information
pfalcon authored and jukkar committed Aug 5, 2017
1 parent 19ff963 commit b7e3739
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions subsys/net/lib/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit b7e3739

Please sign in to comment.