From fa73f130f1560f64c9c9577c948e8fd06d96b9c0 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 17 Nov 2017 21:06:49 +0100 Subject: [PATCH] tcp: fix bug #36167 again (fixed in 2014, but when calling shutdown(WR) followed by recv(), this still happened) --- src/core/tcp.c | 2 +- src/include/lwip/tcpbase.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/tcp.c b/src/core/tcp.c index f418f4c5..dde0632a 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -919,7 +919,7 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len) pcb->rcv_wnd = TCP_WND_MAX(pcb); } else if (pcb->rcv_wnd == 0) { /* rcv_wnd overflowed */ - if ((pcb->state == CLOSE_WAIT) || (pcb->state == LAST_ACK)) { + if (TCP_STATE_IS_CLOSING(pcb->state)) { /* In passive close, we allow this, since the FIN bit is added to rcv_wnd by the stack itself, since it is not mandatory for an application to call tcp_recved() for the FIN bit, but e.g. the netconn API does so. */ diff --git a/src/include/lwip/tcpbase.h b/src/include/lwip/tcpbase.h index 50c28536..00230746 100644 --- a/src/include/lwip/tcpbase.h +++ b/src/include/lwip/tcpbase.h @@ -66,6 +66,8 @@ enum tcp_state { LAST_ACK = 9, TIME_WAIT = 10 }; +/* ATTENTION: this depends on state number ordering! */ +#define TCP_STATE_IS_CLOSING(state) ((state) >= FIN_WAIT_1) /* Flags for "apiflags" parameter in tcp_write */ #define TCP_WRITE_FLAG_COPY 0x01