change tcp_pcb->acked to be a global variable: used in one call stack only (idea by Ambroz Bizjak)

This commit is contained in:
goldsimon 2016-07-19 10:38:01 +02:00
parent c641ae3d3d
commit 6adeb706a6
2 changed files with 23 additions and 23 deletions

View File

@ -75,8 +75,9 @@ static u16_t tcphdr_opt1len;
static u8_t* tcphdr_opt2; static u8_t* tcphdr_opt2;
static u16_t tcp_optidx; static u16_t tcp_optidx;
static u32_t seqno, ackno; static u32_t seqno, ackno;
static u8_t flags; static tcpwnd_size_t recv_acked;
static u16_t tcplen; static u16_t tcplen;
static u8_t flags;
static u8_t recv_flags; static u8_t recv_flags;
static struct pbuf *recv_data; static struct pbuf *recv_data;
@ -346,6 +347,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
recv_data = NULL; recv_data = NULL;
recv_flags = 0; recv_flags = 0;
recv_acked = 0;
if (flags & TCP_PSH) { if (flags & TCP_PSH) {
p->flags |= PBUF_FLAG_PUSH; p->flags |= PBUF_FLAG_PUSH;
@ -380,25 +382,25 @@ tcp_input(struct pbuf *p, struct netif *inp)
/* If the application has registered a "sent" function to be /* If the application has registered a "sent" function to be
called when new send buffer space is available, we call it called when new send buffer space is available, we call it
now. */ now. */
if (pcb->acked > 0) { if (recv_acked > 0) {
u16_t acked; u16_t acked16;
#if LWIP_WND_SCALE #if LWIP_WND_SCALE
/* pcb->acked is u32_t but the sent callback only takes a u16_t, /* recv_acked is u32_t but the sent callback only takes a u16_t,
so we might have to call it multiple times. */ so we might have to call it multiple times. */
u32_t pcb_acked = pcb->acked; u32_t acked = recv_acked;
while (pcb_acked > 0) { while (acked > 0) {
acked = (u16_t)LWIP_MIN(pcb_acked, 0xffffu); acked16 = (u16_t)LWIP_MIN(acked, 0xffffu);
pcb_acked -= acked; acked -= acked16;
#else #else
{ {
acked = pcb->acked; acked16 = recv_acked;
#endif #endif
TCP_EVENT_SENT(pcb, (u16_t)acked, err); TCP_EVENT_SENT(pcb, (u16_t)acked16, err);
if (err == ERR_ABRT) { if (err == ERR_ABRT) {
goto aborted; goto aborted;
} }
} }
pcb->acked = 0; recv_acked = 0;
} }
if (recv_flags & TF_CLOSED) { if (recv_flags & TF_CLOSED) {
/* The connection has been closed and we will deallocate the /* The connection has been closed and we will deallocate the
@ -843,8 +845,8 @@ tcp_process(struct tcp_pcb *pcb)
pcb->ssthresh = LWIP_TCP_INITIAL_SSTHRESH(pcb); pcb->ssthresh = LWIP_TCP_INITIAL_SSTHRESH(pcb);
/* Prevent ACK for SYN to generate a sent event */ /* Prevent ACK for SYN to generate a sent event */
if (pcb->acked != 0) { if (recv_acked != 0) {
pcb->acked--; recv_acked--;
} }
pcb->cwnd = LWIP_TCP_CALC_INITIAL_CWND(pcb->mss); pcb->cwnd = LWIP_TCP_CALC_INITIAL_CWND(pcb->mss);
@ -1060,7 +1062,7 @@ tcp_receive(struct tcp_pcb *pcb)
/* Clause 1 */ /* Clause 1 */
if (TCP_SEQ_LEQ(ackno, pcb->lastack)) { if (TCP_SEQ_LEQ(ackno, pcb->lastack)) {
pcb->acked = 0; recv_acked = 0;
/* Clause 2 */ /* Clause 2 */
if (tcplen == 0) { if (tcplen == 0) {
/* Clause 3 */ /* Clause 3 */
@ -1111,9 +1113,9 @@ tcp_receive(struct tcp_pcb *pcb)
/* Update the send buffer space. Diff between the two can never exceed 64K /* Update the send buffer space. Diff between the two can never exceed 64K
unless window scaling is used. */ unless window scaling is used. */
pcb->acked = (tcpwnd_size_t)(ackno - pcb->lastack); recv_acked = (tcpwnd_size_t)(ackno - pcb->lastack);
pcb->snd_buf += pcb->acked; pcb->snd_buf += recv_acked;
/* Reset the fast retransmit variables. */ /* Reset the fast retransmit variables. */
pcb->dupacks = 0; pcb->dupacks = 0;
@ -1158,8 +1160,8 @@ tcp_receive(struct tcp_pcb *pcb)
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"TCPWNDSIZE_F" ... ", (tcpwnd_size_t)pcb->snd_queuelen)); LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"TCPWNDSIZE_F" ... ", (tcpwnd_size_t)pcb->snd_queuelen));
LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p))); LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p)));
/* Prevent ACK for FIN to generate a sent event */ /* Prevent ACK for FIN to generate a sent event */
if ((pcb->acked != 0) && ((TCPH_FLAGS(next->tcphdr) & TCP_FIN) != 0)) { if ((recv_acked != 0) && ((TCPH_FLAGS(next->tcphdr) & TCP_FIN) != 0)) {
pcb->acked--; recv_acked--;
} }
pcb->snd_queuelen -= pbuf_clen(next->p); pcb->snd_queuelen -= pbuf_clen(next->p);
@ -1190,7 +1192,7 @@ tcp_receive(struct tcp_pcb *pcb)
#endif /* LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS*/ #endif /* LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS*/
} else { } else {
/* Out of sequence ACK, didn't really ack anything */ /* Out of sequence ACK, didn't really ack anything */
pcb->acked = 0; recv_acked = 0;
tcp_send_empty_ack(pcb); tcp_send_empty_ack(pcb);
} }
@ -1217,8 +1219,8 @@ tcp_receive(struct tcp_pcb *pcb)
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"TCPWNDSIZE_F" ... ", (tcpwnd_size_t)pcb->snd_queuelen)); LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"TCPWNDSIZE_F" ... ", (tcpwnd_size_t)pcb->snd_queuelen));
LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p))); LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p)));
/* Prevent ACK for FIN to generate a sent event */ /* Prevent ACK for FIN to generate a sent event */
if ((pcb->acked != 0) && ((TCPH_FLAGS(next->tcphdr) & TCP_FIN) != 0)) { if ((recv_acked != 0) && ((TCPH_FLAGS(next->tcphdr) & TCP_FIN) != 0)) {
pcb->acked--; recv_acked--;
} }
pcb->snd_queuelen -= pbuf_clen(next->p); pcb->snd_queuelen -= pbuf_clen(next->p);
tcp_seg_free(next); tcp_seg_free(next);

View File

@ -264,8 +264,6 @@ struct tcp_pcb {
tcpwnd_size_t snd_wnd; /* sender window */ tcpwnd_size_t snd_wnd; /* sender window */
tcpwnd_size_t snd_wnd_max; /* the maximum sender window announced by the remote host */ tcpwnd_size_t snd_wnd_max; /* the maximum sender window announced by the remote host */
tcpwnd_size_t acked;
tcpwnd_size_t snd_buf; /* Available buffer space for sending (in bytes). */ tcpwnd_size_t snd_buf; /* Available buffer space for sending (in bytes). */
#define TCP_SNDQUEUELEN_OVERFLOW (0xffffU-3) #define TCP_SNDQUEUELEN_OVERFLOW (0xffffU-3)
u16_t snd_queuelen; /* Number of pbufs currently in the send buffer. */ u16_t snd_queuelen; /* Number of pbufs currently in the send buffer. */