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 <blint@blint.hu>
This commit is contained in:
Balint Kovacs 2011-04-20 19:01:19 +02:00
parent 780d221b2f
commit 82da2651b2
1 changed files with 12 additions and 4 deletions

View File

@ -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());
}