From 82da2651b2034114fe6305b922471c9993823092 Mon Sep 17 00:00:00 2001 From: Balint Kovacs Date: Wed, 20 Apr 2011 19:01:19 +0200 Subject: [PATCH] Try to wait() for the workerthreads to finish when stopping the service, this probably needs more thought in the future Signed-off-by: Balint Kovacs --- src/hu/blint/ssldroid/TcpProxyServerThread.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/hu/blint/ssldroid/TcpProxyServerThread.java b/src/hu/blint/ssldroid/TcpProxyServerThread.java index 0bc3690..faa739a 100644 --- a/src/hu/blint/ssldroid/TcpProxyServerThread.java +++ b/src/hu/blint/ssldroid/TcpProxyServerThread.java @@ -186,11 +186,19 @@ public class TcpProxyServerThread extends Thread { } public void run() { - while (true) { + while (true) { try { + + Thread fromBrowserToServer = null; + Thread fromServerToBrowser = null; + if (isInterrupted()){ Log.d("SSLDroid", "Interrupted server thread, closing sockets..."); ss.close(); + if (fromBrowserToServer != null) + fromBrowserToServer.wait(); + if (fromServerToBrowser != null) + fromServerToBrowser.wait(); return; } // accept the connection from my client @@ -220,16 +228,16 @@ public class TcpProxyServerThread extends Thread { + tunnelHost + " ..."); // relay the stuff thru - Thread fromBrowserToServer = new Relay( + fromBrowserToServer = new Relay( sc.getInputStream(), st.getOutputStream()); - Thread fromServerToBrowser = new Relay( + fromServerToBrowser = new Relay( st.getInputStream(), sc.getOutputStream()); fromBrowserToServer.start(); fromServerToBrowser.start(); } catch (Exception ee) { - Log.d("SSLDroid", "Ouch: " + ee.toString()); + Log.d("SSLDroid", "Ouch: " + ee.getMessage()); createNotification(ee.getMessage(), "Ouch: "+ee.toString()); //ttg.doLog("Ouch: " + ee.toString()); }