adb: use TCP keepalive.
Currently adb only realizes a TCP transport has gone away when it tries
to send a packet, which caused problems in particular for `adb reboot`
since no packets are sent, leading to the client hanging until Ctrl+C.
This CL turns on TCP keepalive packets to send 1 packet every second,
allowing up to 10 failures before disconnecting. Using built-in TCP
functionality turns out to be much cleaner in this case than trying to
implement our own keepalive packets at the application layer, and
should be more lightweight since it's all done in the TCP stack.
Bug: http://b/23093474
Change-Id: Ifb41cbb85b9752a9f394e1eed3c6ac4da47a4e4d
(cherry picked from commit bfd9503d1dfc652d0497fa1a5994b3d73e296898)
diff --git a/adb/sysdeps.h b/adb/sysdeps.h
index 7af2979..ce0f289 100644
--- a/adb/sysdeps.h
+++ b/adb/sysdeps.h
@@ -841,4 +841,9 @@
adb_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &off, sizeof(off));
}
+// Sets TCP socket |fd| to send a keepalive TCP message every |interval_sec| seconds. Set
+// |interval_sec| to 0 to disable keepalives. If keepalives are enabled, the connection will be
+// configured to drop after 10 missed keepalives. Returns true on success.
+bool set_tcp_keepalive(int fd, int interval_sec);
+
#endif /* _ADB_SYSDEPS_H */