tcp: Time out connection after 3 attempts, reduce time between resends

This commit is contained in:
K. Lange 2021-09-09 20:17:29 +09:00
parent 548a6314ac
commit 37df43dcaf

View File

@ -687,7 +687,7 @@ static long sock_tcp_connect(sock_t * sock, const struct sockaddr *addr, socklen
unsigned long s, ss;
unsigned long ns, nss;
relative_time(2,0,&s,&ss);
relative_time(1,0,&s,&ss);
int attempts = 0;
while (!sock->rx_queue->length) {
@ -698,14 +698,14 @@ static long sock_tcp_connect(sock_t * sock, const struct sockaddr *addr, socklen
return -ECONNREFUSED;
}
if (result != 0 && (ns > s || (ns == s && nss > ss))) {
if (attempts++ > 5) {
if (attempts++ == 3) {
printf("tcp: connect timed out\n");
free(response);
return -ETIMEDOUT;
}
printf("tcp: retrying...\n");
net_ipv4_send(response,nic);
relative_time(2,0,&s,&ss);
relative_time(1,0,&s,&ss);
}
}