diff options
author | Ben Dodson <bjdodson@google.com> | 2011-06-17 13:50:13 -0700 |
---|---|---|
committer | Ben Dodson <bjdodson@google.com> | 2011-06-17 13:50:39 -0700 |
commit | d1246caeb5eb22aeb7e411e357e89ec945be1d87 (patch) | |
tree | f720221e5058c0dac17900d0560a533cec9929f7 /src | |
parent | 51263896cc43b13d52140d25cced000f7bf6bd2f (diff) | |
download | packages_apps_nfc-d1246caeb5eb22aeb7e411e357e89ec945be1d87.zip packages_apps_nfc-d1246caeb5eb22aeb7e411e357e89ec945be1d87.tar.gz packages_apps_nfc-d1246caeb5eb22aeb7e411e357e89ec945be1d87.tar.bz2 |
Close sockets on failure
Change-Id: I66ec6b12ba6847948e6a69857ea2d9e3c5ee2e17
Diffstat (limited to 'src')
-rwxr-xr-x | src/com/android/nfc/NdefP2pManager.java | 1 | ||||
-rw-r--r-- | src/com/android/nfc/snep/SnepClient.java | 9 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/com/android/nfc/NdefP2pManager.java b/src/com/android/nfc/NdefP2pManager.java index 3e8db67..22270c3 100755 --- a/src/com/android/nfc/NdefP2pManager.java +++ b/src/com/android/nfc/NdefP2pManager.java @@ -174,6 +174,7 @@ public class NdefP2pManager implements SnepServer.Callback { snepClient.connect(); } catch (IOException e) { // Throw exception to fall back to NPP. + snepClient.close(); throw new IOException("SNEP not available.", e); } diff --git a/src/com/android/nfc/snep/SnepClient.java b/src/com/android/nfc/snep/SnepClient.java index 28c3725..01e4fb8 100644 --- a/src/com/android/nfc/snep/SnepClient.java +++ b/src/com/android/nfc/snep/SnepClient.java @@ -117,11 +117,12 @@ public final class SnepClient { mState = CONNECTING; } + LlcpSocket socket = null; SnepMessenger messenger; try { if (DBG) Log.d(TAG, "about to create socket"); // Connect to the snep server on the remote side - LlcpSocket socket = NfcService.getInstance().createLlcpSocket(0, MIU, 1, 1024); + socket = NfcService.getInstance().createLlcpSocket(0, MIU, 1, 1024); if (socket == null) { throw new IOException("Could not connect to socket."); } @@ -137,6 +138,12 @@ public final class SnepClient { int fragmentLength = (mFragmentLength == -1) ? miu : Math.min(miu, mFragmentLength); messenger = new SnepMessenger(true, socket, fragmentLength); } catch (LlcpException e) { + if (socket != null) { + try { + socket.close(); + } catch (IOException e2) { + } + } throw new IOException("Could not connect to socket"); } |