summaryrefslogtreecommitdiffstats
path: root/services/net
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2015-06-04 16:53:25 +0900
committerLorenzo Colitti <lorenzo@google.com>2015-06-04 20:07:14 +0900
commitbe843e8394cd4dee631d4558524241870f577fce (patch)
treeb7e7d41bda4c56795e1172d06f4730f7657e6c1a /services/net
parentcc71518aef42089a5ff5367b8d54c18c01329e13 (diff)
downloadframeworks_base-be843e8394cd4dee631d4558524241870f577fce.zip
frameworks_base-be843e8394cd4dee631d4558524241870f577fce.tar.gz
frameworks_base-be843e8394cd4dee631d4558524241870f577fce.tar.bz2
Actually close sockets when stopping the receive thread.
Contrary to the expectations of the code, IoUtils.closeQuietly() does not unblock system calls. So mReceiveThread.halt() was not actually stopping the receive thread. This wasn't actually a problem, because after "stopping" the receive thread, either the interface would go down (interrupting the previous receive thread with ENETDOWN), or a packet would arrive to both the old and new receive threads, stopping the old one. But the lack of a "stopping receive thread" message at the expected time was confusing. While I'm at it, also add the string for CMD_TIMEOUT. Bug: 19704592 Change-Id: I74732429118af780453028898148519b294fa9d3
Diffstat (limited to 'services/net')
-rw-r--r--services/net/java/android/net/dhcp/DhcpClient.java18
1 files changed, 13 insertions, 5 deletions
diff --git a/services/net/java/android/net/dhcp/DhcpClient.java b/services/net/java/android/net/dhcp/DhcpClient.java
index 069b591..575a300 100644
--- a/services/net/java/android/net/dhcp/DhcpClient.java
+++ b/services/net/java/android/net/dhcp/DhcpClient.java
@@ -58,7 +58,7 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Random;
-import libcore.io.IoUtils;
+import libcore.io.IoBridge;
import static android.system.OsConstants.*;
import static android.net.dhcp.DhcpPacket.*;
@@ -297,9 +297,15 @@ public class DhcpClient extends BaseDhcpStateMachine {
return true;
}
+ private static void closeQuietly(FileDescriptor fd) {
+ try {
+ IoBridge.closeAndSignalBlockedThreads(fd);
+ } catch (IOException ignored) {}
+ }
+
private void closeSockets() {
- IoUtils.closeQuietly(mUdpSock);
- IoUtils.closeQuietly(mPacketSock);
+ closeQuietly(mUdpSock);
+ closeQuietly(mPacketSock);
}
private boolean setIpAddress(LinkAddress address) {
@@ -326,7 +332,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
@Override
public void run() {
- maybeLog("Starting receive thread");
+ maybeLog("Receive thread started");
while (!stopped) {
try {
int length = Os.read(mPacketSock, mPacket, 0, mPacket.length);
@@ -345,7 +351,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
}
}
}
- maybeLog("Stopping receive thread");
+ maybeLog("Receive thread stopped");
}
}
@@ -463,6 +469,8 @@ public class DhcpClient extends BaseDhcpStateMachine {
return "CMD_KICK";
case CMD_RECEIVED_PACKET:
return "CMD_RECEIVED_PACKET";
+ case CMD_TIMEOUT:
+ return "CMD_TIMEOUT";
default:
return Integer.toString(what);
}