Skip to content

Commit

Permalink
net/tcp: fix tcp will not close when tcp retransmission reaches TCP_M…
Browse files Browse the repository at this point in the history
…AXRTX

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 <[email protected]>
  • Loading branch information
Meissi-jian authored and acassis committed May 22, 2024
1 parent 61caf7c commit 0bad215
Showing 1 changed file with 63 additions and 57 deletions.
120 changes: 63 additions & 57 deletions net/tcp/tcp_send_buffered.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 */

if (++TCP_WBNRTX(wrb) >= TCP_MAXRTX)
Expand Down Expand Up @@ -231,6 +203,36 @@ static void retransmit_segment(FAR struct tcp_conn_s *conn,
}
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
* number order). The retransmission will occur below
* when the write buffer with the lowest sequence number
Expand Down Expand Up @@ -859,35 +861,6 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
if (wrb != NULL && TCP_WBSENT(wrb) > 0)
{
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. */

Expand Down Expand Up @@ -924,6 +897,39 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,

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
Expand Down

0 comments on commit 0bad215

Please sign in to comment.