Skip to content

Commit 9cccf0e

Browse files
jukkarnashif
authored andcommitted
net: tcp2: If the send window is full, do not try to send
If there is no space in the sending window, then return -EAGAIN so that the caller may try later. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 29f0895 commit 9cccf0e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

subsys/net/ip/tcp2.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,11 @@ int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt)
14301430

14311431
k_mutex_lock(&conn->lock, K_FOREVER);
14321432

1433+
if (tcp_window_full(conn)) {
1434+
ret = -EAGAIN;
1435+
goto out;
1436+
}
1437+
14331438
len = net_pkt_get_len(pkt);
14341439

14351440
if (conn->send_data->buffer) {

subsys/net/lib/sockets/sockets.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,16 +613,24 @@ ssize_t zsock_sendto_ctx(struct net_context *ctx, const void *buf, size_t len,
613613
}
614614

615615
if (status < 0) {
616-
if (status == -ENOBUFS &&
616+
if (((status == -ENOBUFS) || (status == -EAGAIN)) &&
617617
K_TIMEOUT_EQ(timeout, K_FOREVER)) {
618618
/* If we cannot get any buffers in reasonable
619619
* amount of time, then do not wait forever as
620620
* there might be some bigger issue.
621+
* If we get -EAGAIN and cannot recover, then
622+
* it means that the sending window is blocked
623+
* and we just cannot send anything.
621624
*/
622625
int64_t remaining = buf_timeout - z_tick_get();
623626

624627
if (remaining <= 0) {
625-
errno = ENOMEM;
628+
if (status == -ENOBUFS) {
629+
errno = ENOMEM;
630+
} else {
631+
errno = ENOBUFS;
632+
}
633+
626634
return -1;
627635
}
628636

0 commit comments

Comments
 (0)