Don't try to close server sockets twice.

This may have been the cause of bug #69. Removed the wait-for-shutdown
code in DroidtoothPlugin that was added to attempt to avoid that bug.
This commit is contained in:
akwizgran
2014-05-09 18:16:10 +01:00
parent c86525c1d4
commit eaff042601
4 changed files with 2 additions and 38 deletions

View File

@@ -207,7 +207,6 @@ class DroidtoothPlugin implements DuplexPlugin {
} catch(IOException e) {
// This is expected when the socket is closed
if(LOG.isLoggable(INFO)) LOG.info(e.toString());
tryToClose(socket);
return;
}
if(LOG.isLoggable(INFO)) {
@@ -228,18 +227,8 @@ class DroidtoothPlugin implements DuplexPlugin {
tryToClose(socket);
// Disable Bluetooth if we enabled it and it's still enabled
if(wasDisabled && adapter.isEnabled()) {
// Try to disable the adapter and wait for the result
LOG.info("Disabling Bluetooth");
IntentFilter filter = new IntentFilter(ACTION_STATE_CHANGED);
DisableBluetoothReceiver receiver = new DisableBluetoothReceiver();
appContext.registerReceiver(receiver, filter);
if(adapter.disable()) {
LOG.info("Disabling Bluetooth");
receiver.waitForStateChange();
} else {
LOG.info("Could not disable Bluetooth");
}
appContext.unregisterReceiver(receiver);
if(adapter.disable()) LOG.info("Disabling Bluetooth");
else LOG.info("Could not disable Bluetooth");
}
}
@@ -392,28 +381,6 @@ class DroidtoothPlugin implements DuplexPlugin {
}
}
private class DisableBluetoothReceiver extends BroadcastReceiver {
private final CountDownLatch latch = new CountDownLatch(1);
public void onReceive(Context ctx, Intent intent) {
int state = intent.getIntExtra(EXTRA_STATE, 0);
if(state == STATE_OFF) {
LOG.info("Bluetooth disabled");
latch.countDown();
}
}
private void waitForStateChange() {
try {
latch.await();
} catch(InterruptedException e) {
LOG.info("Interrupted while disabling Bluetooth");
Thread.currentThread().interrupt();
}
}
}
private class DiscoveryThread extends Thread {
private final LatchedReference<BluetoothSocket> socketLatch;

View File

@@ -534,7 +534,6 @@ class TorPlugin implements DuplexPlugin, EventHandler {
} catch(IOException e) {
// This is expected when the socket is closed
if(LOG.isLoggable(INFO)) LOG.info(e.toString());
tryToClose(ss);
return;
}
LOG.info("Connection received");

View File

@@ -139,7 +139,6 @@ abstract class TcpPlugin implements DuplexPlugin {
} catch(IOException e) {
// This is expected when the socket is closed
if(LOG.isLoggable(INFO)) LOG.info(e.toString());
tryToClose(socket);
return;
}
if(LOG.isLoggable(INFO))

View File

@@ -157,7 +157,6 @@ class BluetoothPlugin implements DuplexPlugin {
} catch(IOException e) {
// This is expected when the socket is closed
if(LOG.isLoggable(INFO)) LOG.info(e.toString());
tryToClose(ss);
return;
}
callback.incomingConnectionCreated(wrapSocket(s));