From 3be67e87cf076c53aa98d6f5a0585c96d57823e0 Mon Sep 17 00:00:00 2001 From: jiangheng Date: Wed, 23 Oct 2024 20:52:19 +0800 Subject: [PATCH] fix no ack response when lcoal only receive but not send data --- src/core/tcp.c | 1 + src/core/tcp_in.c | 9 +++++++-- src/core/tcp_out.c | 3 ++- src/include/lwip/tcp.h | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/tcp.c b/src/core/tcp.c index 849a210..b41036e 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -2163,6 +2163,7 @@ tcp_alloc(u8_t prio) #endif #if GAZELLE_TCP_PINGPONG_MODE pcb->lrcvtime = 0; + pcb->lsndtime = 0; pcb->pingpong = 0; #endif pcb_tci_init(pcb); diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index fa2a88b..d0d1e03 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -1766,12 +1766,17 @@ tcp_receive(struct tcp_pcb *pcb) /* Acknowledge the segment(s). */ #if GAZELLE_TCP_PINGPONG_MODE + pcb->lrcvtime = sys_now(); if (tcp_in_pingpong(pcb)) { - tcp_clear_flags(pcb, TF_ACK_NOW | TF_ACK_DELAY); + if (TIME_BEFORE(pcb->lsndtime + TCP_ATO_MS, pcb->lrcvtime)) { + tcp_exit_pingpong(pcb); + tcp_ack_now(pcb); + } else { + tcp_clear_flags(pcb, TF_ACK_NOW | TF_ACK_DELAY); + } } else { tcp_ack(pcb); } - pcb->lrcvtime = sys_now(); #else tcp_ack(pcb); #endif diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 1a55748..93ef958 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1833,8 +1833,9 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif #endif #if GAZELLE_TCP_PINGPONG_MODE + pcb->lsndtime = sys_now(); if (!tcp_in_pingpong(pcb)) { - if (TIME_BEFORE(sys_now(), pcb->lrcvtime + TCP_ATO_MS)) { + if (TIME_BEFORE(pcb->lsndtime, pcb->lrcvtime + TCP_ATO_MS)) { tcp_enter_pingpong(pcb); } } diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h index a332e80..4e41037 100644 --- a/src/include/lwip/tcp.h +++ b/src/include/lwip/tcp.h @@ -304,6 +304,7 @@ struct tcp_pcb { #define TIME_BEFORE(t, compare_to) ((((u32_t)((t)-(compare_to))) > 0x7fffffff) ? 1 : 0) #define TCP_ATO_MS 200 u32_t lrcvtime; + u32_t lsndtime; #define TCP_PINGPONG_THRESH 3 u8_t pingpong; #endif -- 2.33.0