From 5bddbdd914c26a25f90a218e70f6e74e6a1113ae Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 29 Jun 2017 08:47:26 +0200 Subject: [PATCH] tcp_output: faster return when nothing is to send (pcb->unsent == NULL) --- src/core/tcp_out.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index a5000572..9d13e7bb 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1048,26 +1048,6 @@ tcp_output(struct tcp_pcb *pcb) return tcp_send_empty_ack(pcb); } - /* useg should point to last segment on unacked queue */ - useg = pcb->unacked; - if (useg != NULL) { - for (; useg->next != NULL; useg = useg->next); - } - - netif = tcp_route(pcb, &pcb->local_ip, &pcb->remote_ip); - if (netif == NULL) { - return ERR_RTE; - } - - /* If we don't have a local IP address, we get one from netif */ - if (ip_addr_isany(&pcb->local_ip)) { - const ip_addr_t *local_ip = ip_netif_get_local_ip(netif, &pcb->remote_ip); - if (local_ip == NULL) { - return ERR_RTE; - } - ip_addr_copy(pcb->local_ip, *local_ip); - } - #if TCP_OUTPUT_DEBUG if (seg == NULL) { LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: nothing to send (%p)\n", @@ -1095,6 +1075,26 @@ tcp_output(struct tcp_pcb *pcb) goto output_done; } + /* useg should point to last segment on unacked queue */ + useg = pcb->unacked; + if (useg != NULL) { + for (; useg->next != NULL; useg = useg->next); + } + + netif = tcp_route(pcb, &pcb->local_ip, &pcb->remote_ip); + if (netif == NULL) { + return ERR_RTE; + } + + /* If we don't have a local IP address, we get one from netif */ + if (ip_addr_isany(&pcb->local_ip)) { + const ip_addr_t *local_ip = ip_netif_get_local_ip(netif, &pcb->remote_ip); + if (local_ip == NULL) { + return ERR_RTE; + } + ip_addr_copy(pcb->local_ip, *local_ip); + } + /* Check if we need to start the persistent timer when the next unsent segment * does not fit within the remaining send window and RTO timer is not running (we * have no in-flight data). A traditional approach would fill the remaining window