Enable keep alive later and enable on remote close

This will save battery
This commit is contained in:
M66B 2016-03-01 10:15:55 +01:00
parent 2edbef0fdb
commit fd614bcbd7
2 changed files with 17 additions and 4 deletions

View File

@ -48,7 +48,8 @@
#define TCP_RECV_WINDOW 16384 // bytes (maximum)
#define TCP_SEND_WINDOW 16384 // bytes (maximum)
#define TCP_INIT_TIMEOUT 30 // seconds ~net.inet.tcp.keepinit
#define TCP_IDLE_TIMEOUT 300 // seconds ~net.inet.tcp.keepidle
#define TCP_KEEPALIVE_AFTER 1800 // seconds
#define TCP_IDLE_TIMEOUT 3600 // seconds ~net.inet.tcp.keepidle
#define TCP_CLOSE_TIMEOUT 30 // seconds
#define TCP_KEEP_TIMEOUT 300 // seconds
// https://en.wikipedia.org/wiki/Maximum_segment_lifetime

View File

@ -69,9 +69,13 @@ int get_tcp_timeout(const struct tcp_session *t, int sessions, int maxsessions)
if (t->keep_alive)
timeout = TCP_IDLE_TIMEOUT;
else
timeout = TCP_IDLE_TIMEOUT / 2;
} else
timeout = TCP_CLOSE_TIMEOUT;
timeout = TCP_KEEPALIVE_AFTER;
} else {
if (t->state == TCP_CLOSE_WAIT)
timeout = TCP_IDLE_TIMEOUT;
else
timeout = TCP_CLOSE_TIMEOUT;
}
int scale = 100 - sessions * 100 / maxsessions;
timeout = timeout * scale / 100;
@ -626,6 +630,14 @@ jboolean handle_tcp(const struct arguments *args,
}
else
cur->state = TCP_CLOSE_WAIT;
int on = 1;
if (setsockopt(cur->socket, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)))
log_android(ANDROID_LOG_ERROR,
"%s setsockopt SO_KEEPALIVE error %d: %s",
session, errno, strerror(errno));
else
log_android(ANDROID_LOG_WARN, "%s enabled keep alive", session);
}
else if (cur->state == TCP_CLOSE_WAIT) {