tcp_send_buffered.c: Fix snd_wnd

snd_wnd is an offset from the acked sequence number.
This commit is contained in:
YAMAMOTO Takashi 2021-07-19 11:24:06 +09:00 committed by archer
parent 1b82f1c749
commit 42f1851ca6
1 changed files with 107 additions and 94 deletions

View File

@ -781,6 +781,8 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
{ {
FAR struct tcp_wrbuffer_s *wrb; FAR struct tcp_wrbuffer_s *wrb;
uint32_t predicted_seqno; uint32_t predicted_seqno;
uint32_t seq;
uint32_t snd_wnd_edge;
size_t sndlen; size_t sndlen;
/* Peek at the head of the write queue (but don't remove anything /* Peek at the head of the write queue (but don't remove anything
@ -791,28 +793,6 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
wrb = (FAR struct tcp_wrbuffer_s *)sq_peek(&conn->write_q); wrb = (FAR struct tcp_wrbuffer_s *)sq_peek(&conn->write_q);
DEBUGASSERT(wrb); DEBUGASSERT(wrb);
/* Get the amount of data that we can send in the next packet.
* We will send either the remaining data in the buffer I/O
* buffer chain, or as much as will fit given the MSS and current
* window size.
*/
sndlen = TCP_WBPKTLEN(wrb) - TCP_WBSENT(wrb);
if (sndlen > conn->mss)
{
sndlen = conn->mss;
}
if (sndlen > conn->snd_wnd)
{
sndlen = conn->snd_wnd;
}
ninfo("SEND: wrb=%p pktlen=%u sent=%u sndlen=%zu mss=%u "
"snd_wnd=%u\n",
wrb, TCP_WBPKTLEN(wrb), TCP_WBSENT(wrb), sndlen, conn->mss,
conn->snd_wnd);
/* Set the sequence number for this segment. If we are /* Set the sequence number for this segment. If we are
* retransmitting, then the sequence number will already * retransmitting, then the sequence number will already
* be set for this write buffer. * be set for this write buffer.
@ -823,6 +803,37 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
TCP_WBSEQNO(wrb) = conn->isn + conn->sent; TCP_WBSEQNO(wrb) = conn->isn + conn->sent;
} }
/* Get the amount of data that we can send in the next packet.
* We will send either the remaining data in the buffer I/O
* buffer chain, or as much as will fit given the MSS and current
* window size.
*/
seq = TCP_WBSEQNO(wrb) + TCP_WBSENT(wrb);
snd_wnd_edge = conn->snd_wl2 + conn->snd_wnd;
if (TCP_SEQ_LT(seq, snd_wnd_edge))
{
uint32_t remaining_snd_wnd;
sndlen = TCP_WBPKTLEN(wrb) - TCP_WBSENT(wrb);
if (sndlen > conn->mss)
{
sndlen = conn->mss;
}
remaining_snd_wnd = TCP_SEQ_SUB(snd_wnd_edge, seq);
if (sndlen > remaining_snd_wnd)
{
sndlen = remaining_snd_wnd;
}
ninfo("SEND: wrb=%p seq=%" PRIu32 " pktlen=%u sent=%u sndlen=%zu "
"mss=%u snd_wnd=%u seq=%" PRIu32
" remaining_snd_wnd=%" PRIu32 "\n",
wrb, TCP_WBSEQNO(wrb), TCP_WBPKTLEN(wrb), TCP_WBSENT(wrb),
sndlen, conn->mss,
conn->snd_wnd, seq, remaining_snd_wnd);
/* The TCP stack updates sndseq on receipt of ACK *before* /* The TCP stack updates sndseq on receipt of ACK *before*
* this function is called. In that case sndseq will point * this function is called. In that case sndseq will point
* to the next unacknowledged byte (which might have already * to the next unacknowledged byte (which might have already
@ -868,7 +879,8 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
conn->sndseq_max = predicted_seqno; conn->sndseq_max = predicted_seqno;
} }
ninfo("SEND: wrb=%p nrtx=%u tx_unacked=%" PRIu32 " sent=%" PRIu32 "\n", ninfo("SEND: wrb=%p nrtx=%u tx_unacked=%" PRIu32
" sent=%" PRIu32 "\n",
wrb, TCP_WBNRTX(wrb), conn->tx_unacked, conn->sent); wrb, TCP_WBNRTX(wrb), conn->tx_unacked, conn->sent);
/* Increment the count of bytes sent from this write buffer */ /* Increment the count of bytes sent from this write buffer */
@ -906,6 +918,7 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
flags &= ~TCP_POLL; flags &= ~TCP_POLL;
} }
}
/* Continue waiting */ /* Continue waiting */