Skip to content

Commit

Permalink
net/tcp_timer: fix tcp_timer idle loop and transmit bug
Browse files Browse the repository at this point in the history
1. Tcp will idle loop by tcp_timer when have no packet to send. This will cause low-power devices to be frequently woken up.
2. We should add tcp_timer when timer has been canceled and have packet to send.

Signed-off-by: meijian <[email protected]>
  • Loading branch information
Meissi-jian committed Aug 24, 2024
1 parent 6071102 commit f881b94
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 13 additions & 5 deletions net/tcp/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ static void tcp_input(FAR struct net_driver_s *dev, uint8_t domain,
{
uint32_t unackseq;
uint32_t ackseq;
int timeout;

/* The next sequence number is equal to the current sequence
* number (sndseq) plus the size of the outstanding, unacknowledged
Expand Down Expand Up @@ -1137,9 +1138,20 @@ static void tcp_input(FAR struct net_driver_s *dev, uint8_t domain,

flags |= TCP_ACKDATA;

/* Check if no packet need to retransmission, clear timer. */

if (conn->tx_unacked == 0 && conn->tcpstateflags == TCP_ESTABLISHED)
{
timeout = 0;
}
else
{
timeout = conn->rto;
}

/* Reset the retransmission timer. */

tcp_update_retrantimer(conn, conn->rto);
tcp_update_retrantimer(conn, timeout);
}

/* Check if the sequence number of the incoming packet is what we are
Expand Down Expand Up @@ -1208,10 +1220,6 @@ static void tcp_input(FAR struct net_driver_s *dev, uint8_t domain,
/* Window updated, set the acknowledged flag. */

flags |= TCP_ACKDATA;

/* Reset the retransmission timer. */

tcp_update_retrantimer(conn, conn->rto);
}
}

Expand Down
7 changes: 7 additions & 0 deletions net/tcp/tcp_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <nuttx/net/netstats.h>
#include <nuttx/net/ip.h>
#include <nuttx/net/tcp.h>
#include <nuttx/wqueue.h>

#include "netdev/netdev.h"
#include "devif/devif.h"
Expand Down Expand Up @@ -146,6 +147,12 @@ static void tcp_sendcommon(FAR struct net_driver_s *dev,
}
else
{
if (work_available(&conn->work) && conn->tx_unacked != 0)
{
conn->timeout = false;
tcp_update_retrantimer(conn, conn->rto);
}

/* Update the TCP received window based on I/O buffer availability */

uint32_t rcvseq = tcp_getsequence(conn->rcvseq);
Expand Down

0 comments on commit f881b94

Please sign in to comment.