diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index 99d4b5171f3..e5d81570ea8 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -1107,7 +1107,7 @@ static int tcp_send_queued_data(struct tcp *conn) (void)k_sem_take(&conn->tx_sem, K_NO_WAIT); } - if (conn->unacked_len) { + if (conn->send_data_total) { subscribe = true; } @@ -1115,14 +1115,6 @@ static int tcp_send_queued_data(struct tcp *conn) subscribe = false; } - /* If we have out-of-bufs case, then do not start retransmit timer - * yet. The socket layer will catch this and resend data if needed. - */ - if (ret == -ENOBUFS) { - NET_DBG("No bufs, cancelling retransmit timer"); - k_work_cancel_delayable(&conn->send_data_timer); - } - if (subscribe) { conn->send_data_retries = 0; k_work_reschedule_for_queue(&tcp_work_q, &conn->send_data_timer, @@ -2370,6 +2362,18 @@ int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt) pkt->buffer = conn->send_data->buffer; conn->send_data->buffer = NULL; } + + /* If we have out-of-bufs case, and the send_data buffer has + * become empty, till the retransmit timer, as there is no + * data to retransmit. + * The socket layer will catch this and resend data if needed. + * Only perform this when it is just the newly added packet, + * otherwise it can disrupt any pending transmission + */ + if (conn->send_data_total == 0) { + NET_DBG("No bufs, cancelling retransmit timer"); + k_work_cancel_delayable(&conn->send_data_timer); + } } else { /* We should not free the pkt if there was an error. It will be * freed in net_context.c:context_sendto()