Fix host-descriptor deleter specialisation.

This commit is contained in:
2019-09-06 13:03:13 +01:00
parent dac4617d70
commit 5921e6ea48

View File

@@ -36,7 +36,7 @@ using std::runtime_error;
using std::shared_ptr; using std::shared_ptr;
using std::string; using std::string;
int initialiseHostDescriptor(); shared_ptr<int> initialiseHostDescriptor();
#ifdef DEBUG_STREAMS #ifdef DEBUG_STREAMS
@@ -47,11 +47,7 @@ void closeHTML(FILE* fPtr);
#endif #endif
shared_ptr<int> getHostDescriptor() { shared_ptr<int> getHostDescriptor() {
static shared_ptr<int> descriptor{ new int{ initialiseHostDescriptor() }, [](const int* fd) { static shared_ptr<int> descriptor{ initialiseHostDescriptor() };
close(*fd);
delete fd;
} };
return descriptor; return descriptor;
} }
@@ -195,7 +191,7 @@ void closeHTML(FILE* fPtr) {
#endif #endif
int initialiseHostDescriptor() { shared_ptr<int> initialiseHostDescriptor() {
int descriptor; int descriptor;
#ifdef HID_SOCKET #ifdef HID_SOCKET
@@ -229,12 +225,21 @@ int initialiseHostDescriptor() {
throw runtime_error{ "Unable to connect to server socket: " + string{ HID_DEV } }; throw runtime_error{ "Unable to connect to server socket: " + string{ HID_DEV } };
__android_log_print(ANDROID_LOG_DEBUG, "U2FDevice", "Connected to server"); __android_log_print(ANDROID_LOG_DEBUG, "U2FDevice", "Connected to server");
return shared_ptr<int>{ new int{ descriptor }, [](const int* fd) {
close(*fd);
remove(clientSocket.c_str());
delete fd;
} };
#else #else
descriptor = open(HID_DEV, O_RDWR | O_NONBLOCK | O_APPEND); descriptor = open(HID_DEV, O_RDWR | O_NONBLOCK | O_APPEND);
if (descriptor == -1) if (descriptor == -1)
throw runtime_error{ "Descriptor is unavailable" }; throw runtime_error{ "Descriptor is unavailable" };
#endif
return descriptor; return shared_ptr<int>{ new int{ descriptor }, [](const int* fd) {
close(*fd);
delete fd;
} };
#endif
} }