continue;
}
- c->rtrx_timeout = now;
- c->conn_timeout = then;
+ if(timerisset(&c->rtrx_timeout)) {
+ c->rtrx_timeout = now;
+ }
+
+ if(timerisset(&c->conn_timeout)) {
+ c->conn_timeout = then;
+ }
+
c->rtt_start.tv_sec = 0;
}
}
void utcp_offline(struct utcp *utcp, bool offline) {
+ struct timeval now;
+ gettimeofday(&now, NULL);
+
for(int i = 0; i < utcp->nconnections; i++) {
struct utcp_connection *c = utcp->connections[i];
- if(!c->reapable) {
- utcp_expect_data(c, offline);
-
- // If we are online again, reset the retransmission timers, but keep the connection timeout as it is,
- // to prevent peers toggling online/offline state frequently from keeping connections alive
- // if there is no progress in sending actual data.
- if(!offline) {
- gettimeofday(&utcp->connections[i]->rtrx_timeout, NULL);
- utcp->connections[i]->rtt_start.tv_sec = 0;
+ if(c->reapable) {
+ continue;
+ }
+
+ utcp_expect_data(c, offline);
+
+ if(!offline) {
+ if(timerisset(&c->rtrx_timeout)) {
+ c->rtrx_timeout = now;
}
+
+ utcp->connections[i]->rtt_start.tv_sec = 0;
}
}