- public void cancel() {
- try {
- if (tmp_socket != null)
- tmp_socket.close();
- } catch (IOException e) {
- Log.e(TAG, "close() of connect " + mSocketType + " socket failed", e);
+ BluetoothSocket local_socket = null;
+
+ synchronized (AltosBluetooth.this) {
+ if (!closed())
+ local_socket = socket;
+ }
+
+ if (local_socket != null) {
+ try {
+ // Make a connection to the BluetoothSocket
+ // This is a blocking call and will only return on a
+ // successful connection or an exception
+ local_socket.connect();
+ } catch (Exception e) {
+ AltosDebug.debug("Connect exception %s", e.toString());
+ try {
+ local_socket.close();
+ } catch (Exception ce) {
+ AltosDebug.debug("Close exception %s", ce.toString());
+ }
+ local_socket = null;
+ }
+ }
+
+ if (local_socket != null) {
+ connected();
+ } else {
+ connect_failed();