summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMaksymilian Osowski <maxosowski@google.com>2010-09-02 03:36:57 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-09-02 03:36:57 -0700
commit15116bcc766626654655875fb96154c93df54668 (patch)
tree147a3ebb175c1c71ef3285ace3caa3b2033a51e0 /tests
parent4cf63e57ac5dbc1e376a7d5d2ba4a59cbbb585c5 (diff)
parent5926723f82fbdd9b523193e05f901784904b6d38 (diff)
downloadframeworks_base-15116bcc766626654655875fb96154c93df54668.zip
frameworks_base-15116bcc766626654655875fb96154c93df54668.tar.gz
frameworks_base-15116bcc766626654655875fb96154c93df54668.tar.bz2
Merge "Fixed a bug when there are too many open sockets."
Diffstat (limited to 'tests')
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java25
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java29
2 files changed, 48 insertions, 6 deletions
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java
index 2ffb48f..c356a10 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java
@@ -32,6 +32,10 @@ public class ConnectionHandler {
private static final String LOG_TAG = "ConnectionHandler";
+ public static interface OnFinishedCallback {
+ public void onFinished();
+ }
+
private class SocketPipeThread extends Thread {
private Socket mInSocket, mOutSocket;
@@ -69,6 +73,9 @@ public class ConnectionHandler {
break;
}
}
+
+ ConnectionHandler.this.stop();
+ mOnFinishedCallback.onFinished();
}
@Override
@@ -80,6 +87,8 @@ public class ConnectionHandler {
private Socket mFromSocket, mToSocket;
private SocketPipeThread mFromToPipe, mToFromPipe;
+ private OnFinishedCallback mOnFinishedCallback;
+
public ConnectionHandler(Socket fromSocket, Socket toSocket) {
mFromSocket = fromSocket;
mToSocket = toSocket;
@@ -87,6 +96,10 @@ public class ConnectionHandler {
mToFromPipe = new SocketPipeThread(mToSocket, mFromSocket);
}
+ public void registerOnConnectionHandlerFinishedCallback(OnFinishedCallback callback) {
+ mOnFinishedCallback = callback;
+ }
+
public void start() {
mFromToPipe.start();
mToFromPipe.start();
@@ -102,17 +115,23 @@ public class ConnectionHandler {
synchronized (mToFromPipe) {
/** This will stop the while loop in the run method */
try {
- socket.shutdownInput();
+ if (!socket.isInputShutdown()) {
+ socket.shutdownInput();
+ }
} catch (IOException e) {
Log.e(LOG_TAG, "mFromToPipe=" + mFromToPipe + " mToFromPipe=" + mToFromPipe, e);
}
try {
- socket.shutdownOutput();
+ if (!socket.isOutputShutdown()) {
+ socket.shutdownOutput();
+ }
} catch (IOException e) {
Log.e(LOG_TAG, "mFromToPipe=" + mFromToPipe + " mToFromPipe=" + mToFromPipe, e);
}
try {
- socket.close();
+ if (!socket.isClosed()) {
+ socket.close();
+ }
} catch (IOException e) {
Log.e(LOG_TAG, "mFromToPipe=" + mFromToPipe + " mToFromPipe=" + mToFromPipe, e);
}
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java
index f948767..1b581fc 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java
@@ -92,14 +92,37 @@ public class Forwarder extends Thread {
continue;
}
- ConnectionHandler forwarder = new ConnectionHandler(localSocket, remoteSocket);
- mConnectionHandlers.add(forwarder);
- forwarder.start();
+ final ConnectionHandler connectionHandler =
+ new ConnectionHandler(localSocket, remoteSocket);
+
+ /**
+ * We have to close the sockets after the ConnectionHandler finishes, so we
+ * don't get "Too may open files" exception. We also remove the ConnectionHandler
+ * from the collection to avoid memory issues.
+ * */
+ ConnectionHandler.OnFinishedCallback callback =
+ new ConnectionHandler.OnFinishedCallback() {
+ @Override
+ public void onFinished() {
+ removeConncetionHandler(connectionHandler);
+ }
+ };
+ connectionHandler.registerOnConnectionHandlerFinishedCallback(callback);
+ mConnectionHandlers.add(connectionHandler);
+ connectionHandler.start();
}
}
}
+ private synchronized void removeConncetionHandler(ConnectionHandler connectionHandler) {
+ if (mConnectionHandlers.remove(connectionHandler)) {
+ Log.d(LOG_TAG, "removeConnectionHandler(): removed");
+ } else {
+ Log.d(LOG_TAG, "removeConnectionHandler(): not in the collection");
+ }
+ }
+
public void finish() {
try {
mServerSocket.close();