Everytime Bluetooth was turned off two file descriptors were not closed
Using close instead of shutdown on the file descriptors and only clear the file
descriptor that was closed. If both file descriptors are cleared the thread
will not be able to close it.
diff --git a/core/jni/android_server_BluetoothEventLoop.cpp b/core/jni/android_server_BluetoothEventLoop.cpp
index d2e9454..fdc97ee 100644
--- a/core/jni/android_server_BluetoothEventLoop.cpp
+++ b/core/jni/android_server_BluetoothEventLoop.cpp
@@ -564,7 +564,10 @@
NULL, NULL, NULL, NULL, NULL);
tearDownEventLoop(nat);
nat->vm->DetachCurrentThread();
- shutdown(nat->controlFdR,SHUT_RDWR);
+
+ int fd = nat->controlFdR;
+ nat->controlFdR = 0;
+ close(fd);
return NULL;
}
case EVENT_LOOP_ADD:
@@ -653,9 +656,12 @@
done:
if (JNI_FALSE == result) {
- if (nat->controlFdW || nat->controlFdR) {
- shutdown(nat->controlFdW, SHUT_RDWR);
+ if (nat->controlFdW) {
+ close(nat->controlFdW);
nat->controlFdW = 0;
+ }
+ if (nat->controlFdR) {
+ close(nat->controlFdR);
nat->controlFdR = 0;
}
if (nat->me) env->DeleteGlobalRef(nat->me);
@@ -692,9 +698,10 @@
nat->watchData = NULL;
nat->pollDataSize = 0;
nat->pollMemberCount = 0;
- shutdown(nat->controlFdW, SHUT_RDWR);
+
+ int fd = nat->controlFdW;
nat->controlFdW = 0;
- nat->controlFdR = 0;
+ close(fd);
}
pthread_mutex_unlock(&(nat->thread_mutex));
#endif // HAVE_BLUETOOTH