net/tcp: Use the decrease timer in TCP_TIME_WAIT/TCP_FIN_WAIT_2
unify the timer process logic as other tcp state Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
aefe78a884
commit
2d3ee157ce
@ -664,7 +664,7 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain)
|
||||
{
|
||||
/* Yes.. Is it the oldest one we have seen so far? */
|
||||
|
||||
if (!conn || tmp->timer > conn->timer)
|
||||
if (!conn || tmp->timer < conn->timer)
|
||||
{
|
||||
/* Yes.. remember it */
|
||||
|
||||
|
@ -1229,7 +1229,7 @@ found:
|
||||
if ((flags & TCP_ACKDATA) != 0 && conn->tx_unacked == 0)
|
||||
{
|
||||
conn->tcpstateflags = TCP_TIME_WAIT;
|
||||
conn->timer = 0;
|
||||
conn->timer = TCP_TIME_WAIT_TIMEOUT * HSEC_PER_SEC;
|
||||
ninfo("TCP state: TCP_TIME_WAIT\n");
|
||||
}
|
||||
else
|
||||
@ -1267,7 +1267,7 @@ found:
|
||||
if ((tcp->flags & TCP_FIN) != 0)
|
||||
{
|
||||
conn->tcpstateflags = TCP_TIME_WAIT;
|
||||
conn->timer = 0;
|
||||
conn->timer = TCP_TIME_WAIT_TIMEOUT * HSEC_PER_SEC;
|
||||
ninfo("TCP state: TCP_TIME_WAIT\n");
|
||||
|
||||
net_incr32(conn->rcvseq, 1); /* ack FIN */
|
||||
@ -1292,7 +1292,7 @@ found:
|
||||
if ((flags & TCP_ACKDATA) != 0)
|
||||
{
|
||||
conn->tcpstateflags = TCP_TIME_WAIT;
|
||||
conn->timer = 0;
|
||||
conn->timer = TCP_TIME_WAIT_TIMEOUT * HSEC_PER_SEC;
|
||||
ninfo("TCP state: TCP_TIME_WAIT\n");
|
||||
}
|
||||
|
||||
|
@ -167,19 +167,13 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
|
||||
if (conn->tcpstateflags == TCP_TIME_WAIT ||
|
||||
conn->tcpstateflags == TCP_FIN_WAIT_2)
|
||||
{
|
||||
unsigned int newtimer;
|
||||
|
||||
/* Increment the connection timer */
|
||||
|
||||
newtimer = (unsigned int)conn->timer + hsec;
|
||||
|
||||
/* Check if the timer exceeds the timeout value */
|
||||
|
||||
if (newtimer >= (TCP_TIME_WAIT_TIMEOUT * HSEC_PER_SEC))
|
||||
if (conn->timer <= hsec)
|
||||
{
|
||||
/* Set the timer to the maximum value */
|
||||
/* Set the timer to zero value */
|
||||
|
||||
conn->timer = TCP_TIME_WAIT_TIMEOUT * HSEC_PER_SEC;
|
||||
conn->timer = 0;
|
||||
conn->tcpstateflags = TCP_CLOSED;
|
||||
|
||||
/* Notify upper layers about the timeout */
|
||||
@ -190,9 +184,9 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No timeout. Just update the incremented timer */
|
||||
/* No timeout. Just update the decremented timer */
|
||||
|
||||
conn->timer = newtimer;
|
||||
conn->timer -= hsec;
|
||||
}
|
||||
}
|
||||
else if (conn->tcpstateflags != TCP_CLOSED)
|
||||
@ -301,7 +295,7 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
|
||||
/* Exponential backoff. */
|
||||
|
||||
conn->timer = TCP_RTO << (conn->nrtx > 4 ? 4: conn->nrtx);
|
||||
(conn->nrtx)++;
|
||||
conn->nrtx++;
|
||||
|
||||
/* Ok, so we need to retransmit. We do this differently
|
||||
* depending on which state we are in. In ESTABLISHED, we
|
||||
|
Loading…
Reference in New Issue
Block a user