From abd3142dcae02026689b939c363329b822b7cc0a Mon Sep 17 00:00:00 2001 From: Erik Kline Date: Fri, 15 May 2015 18:49:17 +0900 Subject: Close netlink socket when shutting down IpReachabilityMonitor This forces the NetlinkSocketObserver thread to exit quickly, rather than lingering until the next random netlink neighbor multicast message arrives. Additionally, add a small unittest to verify that multiple calls to NetlinkSocket#close() are safe. Change-Id: I101730fad7eee72f9c6e8a7e7bd10c634f2ceab4 --- .../src/android/net/netlink/NetlinkSocketTest.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'core/tests') diff --git a/core/tests/coretests/src/android/net/netlink/NetlinkSocketTest.java b/core/tests/coretests/src/android/net/netlink/NetlinkSocketTest.java index b32de78..c599fe3 100644 --- a/core/tests/coretests/src/android/net/netlink/NetlinkSocketTest.java +++ b/core/tests/coretests/src/android/net/netlink/NetlinkSocketTest.java @@ -90,4 +90,27 @@ public class NetlinkSocketTest extends TestCase { s.close(); } + + public void testRepeatedCloseCallsAreQuiet() throws Exception { + // Create a working NetlinkSocket. + NetlinkSocket s = new NetlinkSocket(OsConstants.NETLINK_ROUTE); + assertNotNull(s); + s.connectToKernel(); + NetlinkSocketAddress localAddr = s.getLocalAddress(); + assertNotNull(localAddr); + assertEquals(0, localAddr.getGroupsMask()); + assertTrue(0 != localAddr.getPortId()); + // Close once. + s.close(); + // Test that it is closed. + boolean expectedErrorSeen = false; + try { + localAddr = s.getLocalAddress(); + } catch (ErrnoException e) { + expectedErrorSeen = true; + } + assertTrue(expectedErrorSeen); + // Close once more. + s.close(); + } } -- cgit v1.1