adb: detect sockets in CLOSE_WAIT state to prevent socket leak on linux.
It is possible that the adb server on host has many sockets in
CLOSE_WAIT state. To prevent socket leak, always enable POLLRDHUP
in fdevent.cpp to detect sockets in CLOSE_WAIT state.
Update LocalSocketTest unit tests:
Change half_close_with_packet to read_from_closing_socket, as reading
from a SHUT_WR socket is not needed in adb.
Change close_with_no_events_installed to close_socket_in_CLOSE_WAIT_state,
as the latter is more close to the real situation in use.
Bug: 23314034
Change-Id: Ice4f4036624e5584eab6ba5848e7f169c92f037f
diff --git a/adb/adb.cpp b/adb/adb.cpp
index 0e1859c..1c1683e 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -395,6 +395,11 @@
D("Invalid A_OKAY(%d,%d), expected A_OKAY(%d,%d) on transport %s",
p->msg.arg0, p->msg.arg1, s->peer->id, p->msg.arg1, t->serial);
}
+ } else {
+ // When receiving A_OKAY from device for A_OPEN request, the host server may
+ // have closed the local socket because of client disconnection. Then we need
+ // to send A_CLSE back to device to close the service on device.
+ send_close(p->msg.arg1, p->msg.arg0, t);
}
}
break;