From 6fa5d02435ba8893efacd5acd9736b0752fe964e Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Thu, 3 Aug 2017 10:37:16 -0500 Subject: [PATCH] tcp: remove extra seg == NULL checks In tcp_output() there were a number of blocks of code performing duplicate checks of 'if (seg == NULL)'. This combines them together to reduce duplicate checks TCP_OUTPUT_DEBUG and TCP_CWND_DEBUG also don't need to be guarded by #if/#endif since the LWIP_DEBUGF infrastructure already compiles them out when LWIP_DEBUG is not defined --- src/core/tcp_out.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 533e76eb..3f6ef8ac 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1139,18 +1139,15 @@ tcp_output(struct tcp_pcb *pcb) return tcp_send_empty_ack(pcb); } -#if TCP_OUTPUT_DEBUG if (seg == NULL) { LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: nothing to send (%p)\n", (void*)pcb->unsent)); - } -#endif /* TCP_OUTPUT_DEBUG */ -#if TCP_CWND_DEBUG - if (seg == NULL) { LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"TCPWNDSIZE_F ", cwnd %"TCPWNDSIZE_F", wnd %"U32_F ", seg == NULL, ack %"U32_F"\n", pcb->snd_wnd, pcb->cwnd, wnd, pcb->lastack)); + /* nothing to send: shortcut out of here */ + goto output_done; } else { LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"TCPWNDSIZE_F", cwnd %"TCPWNDSIZE_F", wnd %"U32_F @@ -1159,12 +1156,6 @@ tcp_output(struct tcp_pcb *pcb) lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len, lwip_ntohl(seg->tcphdr->seqno), pcb->lastack)); } -#endif /* TCP_CWND_DEBUG */ - - if (seg == NULL) { - /* nothing to send: shortcut out of here */ - goto output_done; - } /* useg should point to last segment on unacked queue */ useg = pcb->unacked; @@ -1194,8 +1185,7 @@ tcp_output(struct tcp_pcb *pcb) * subsequent window update is reliably received. With the goal of being lightweight, * we avoid splitting the unsent segment and treat the window as already zero. */ - if (seg != NULL && - lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd && + if (lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd && wnd > 0 && wnd == pcb->snd_wnd && pcb->unacked == NULL) { /* Start the persist timer */ if (pcb->persist_backoff == 0) {