net/tcp: fix tcp will not close when tcp retransmission reaches TCP_MAXRTX

In "psock_send_eventhandler",when retransmit count bigger TCP_MAXRTX nuttx will set release wrb. But before this it will also set "conn->tx_unacked = 0" if we only retransmit one packet(conn->tx_unacked == sent),and In func "tcp_timer" only "conn->tx_unacked > 0" will close the tcp conn. So app will never close if nuttx retransmit over max timers.

Signed-off-by: meijian <meijian@xiaomi.com>
This commit is contained in:
meijian 2024-05-21 10:51:06 +08:00 committed by Alan Carvalho de Assis
parent 61caf7cce9
commit 0bad215cf8
1 changed files with 63 additions and 57 deletions

View File

@ -173,34 +173,6 @@ static void psock_writebuffer_notify(FAR struct tcp_conn_s *conn)
static void retransmit_segment(FAR struct tcp_conn_s *conn, static void retransmit_segment(FAR struct tcp_conn_s *conn,
FAR struct tcp_wrbuffer_s *wrb) FAR struct tcp_wrbuffer_s *wrb)
{ {
uint16_t sent;
/* Reset the number of bytes sent sent from the write buffer */
sent = TCP_WBSENT(wrb);
if (conn->tx_unacked > sent)
{
conn->tx_unacked -= sent;
}
else
{
conn->tx_unacked = 0;
}
if (conn->sent > sent)
{
conn->sent -= sent;
}
else
{
conn->sent = 0;
}
TCP_WBSENT(wrb) = 0;
ninfo("REXMIT: wrb=%p sent=%u, "
"conn tx_unacked=%" PRId32 " sent=%" PRId32 "\n",
wrb, TCP_WBSENT(wrb), conn->tx_unacked, conn->sent);
/* Free any write buffers that have exceed the retry count */ /* Free any write buffers that have exceed the retry count */
if (++TCP_WBNRTX(wrb) >= TCP_MAXRTX) if (++TCP_WBNRTX(wrb) >= TCP_MAXRTX)
@ -231,6 +203,36 @@ static void retransmit_segment(FAR struct tcp_conn_s *conn,
} }
else else
{ {
uint16_t sent;
sent = TCP_WBSENT(wrb);
ninfo("REXMIT: wrb=%p sent=%u, "
"conn tx_unacked=%" PRId32 " sent=%" PRId32 "\n",
wrb, TCP_WBSENT(wrb), conn->tx_unacked, conn->sent);
/* Reset the number of bytes sent sent from the write buffer */
if (conn->tx_unacked > sent)
{
conn->tx_unacked -= sent;
}
else
{
conn->tx_unacked = 0;
}
if (conn->sent > sent)
{
conn->sent -= sent;
}
else
{
conn->sent = 0;
}
TCP_WBSENT(wrb) = 0;
/* Insert the write buffer into the write_q (in sequence /* Insert the write buffer into the write_q (in sequence
* number order). The retransmission will occur below * number order). The retransmission will occur below
* when the write buffer with the lowest sequence number * when the write buffer with the lowest sequence number
@ -859,35 +861,6 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
if (wrb != NULL && TCP_WBSENT(wrb) > 0) if (wrb != NULL && TCP_WBSENT(wrb) > 0)
{ {
FAR struct tcp_wrbuffer_s *tmp; FAR struct tcp_wrbuffer_s *tmp;
uint16_t sent;
/* Yes.. Reset the number of bytes sent sent from
* the write buffer
*/
sent = TCP_WBSENT(wrb);
if (conn->tx_unacked > sent)
{
conn->tx_unacked -= sent;
}
else
{
conn->tx_unacked = 0;
}
if (conn->sent > sent)
{
conn->sent -= sent;
}
else
{
conn->sent = 0;
}
TCP_WBSENT(wrb) = 0;
ninfo("REXMIT: wrb=%p sent=%u, "
"conn tx_unacked=%" PRId32 " sent=%" PRId32 "\n",
wrb, TCP_WBSENT(wrb), conn->tx_unacked, conn->sent);
/* Increment the retransmit count on this write buffer. */ /* Increment the retransmit count on this write buffer. */
@ -924,6 +897,39 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
conn->expired++; conn->expired++;
} }
else
{
uint16_t sent;
sent = TCP_WBSENT(wrb);
ninfo("REXMIT: wrb=%p sent=%u, "
"conn tx_unacked=%" PRId32 " sent=%" PRId32 "\n",
wrb, TCP_WBSENT(wrb), conn->tx_unacked, conn->sent);
/* Yes.. Reset the number of bytes sent sent from
* the write buffer
*/
if (conn->tx_unacked > sent)
{
conn->tx_unacked -= sent;
}
else
{
conn->tx_unacked = 0;
}
if (conn->sent > sent)
{
conn->sent -= sent;
}
else
{
conn->sent = 0;
}
TCP_WBSENT(wrb) = 0;
}
} }
/* Move all segments that have been sent but not ACKed to the write /* Move all segments that have been sent but not ACKed to the write