diff options
author | Nikias Bassen | 2016-06-26 18:30:40 +0200 |
---|---|---|
committer | Nikias Bassen | 2016-06-26 18:30:40 +0200 |
commit | a4df93a83cae154611377beb5254015dc95640b9 (patch) | |
tree | 883be3184d4174803a2deb04a9fda59b0df728ba /src | |
parent | 3e8651102df3a694c8e88a73b8d8d753f8d760c6 (diff) | |
download | idevicerestore-a4df93a83cae154611377beb5254015dc95640b9.tar.gz idevicerestore-a4df93a83cae154611377beb5254015dc95640b9.tar.bz2 |
fdr: Add fdr_disconnect() function to stop the FDR thread
Diffstat (limited to 'src')
-rw-r--r-- | src/fdr.c | 21 | ||||
-rw-r--r-- | src/fdr.h | 1 |
2 files changed, 17 insertions, 5 deletions
@@ -108,15 +108,25 @@ int fdr_connect(idevice_t device, fdr_type_t type, fdr_client_t* fdr) return 0; } -void fdr_free(fdr_client_t fdr) +void fdr_disconnect(fdr_client_t fdr) { if (!fdr) return; if (fdr->connection) { - idevice_disconnect(fdr->connection); + idevice_connection_t conn = fdr->connection; fdr->connection = NULL; + idevice_disconnect(conn); } +} + +void fdr_free(fdr_client_t fdr) +{ + if (!fdr) + return; + + fdr_disconnect(fdr); + free(fdr); fdr = NULL; } @@ -134,8 +144,9 @@ int fdr_poll_and_handle_message(fdr_client_t fdr) device_error = idevice_connection_receive_timeout(fdr->connection, (char *)&cmd, sizeof(cmd), &bytes, 20000); if (device_error != IDEVICE_E_SUCCESS) { - error("ERROR: Unable to receive message from FDR %p (%d). %u/%d bytes\n", - fdr, device_error, bytes, sizeof(cmd)); + if (fdr->connection) { + error("ERROR: Unable to receive message from FDR %p (%d). %u/%d bytes\n", fdr, device_error, bytes, sizeof(cmd)); + } return -1; } else if (bytes != sizeof(cmd)) { debug("FDR %p timeout waiting for command\n", fdr); @@ -166,7 +177,7 @@ void *fdr_listener_thread(void *cdata) fdr_client_t fdr = cdata; int res; - while (1) { + while (fdr && fdr->connection) { debug("FDR %p waiting for message...\n", fdr); res = fdr_poll_and_handle_message(fdr); if (fdr->type == FDR_CTRL && res >= 0) @@ -42,6 +42,7 @@ struct fdr_client { typedef struct fdr_client *fdr_client_t; int fdr_connect(idevice_t device, fdr_type_t type, fdr_client_t *fdr); +void fdr_disconnect(fdr_client_t fdr); void fdr_free(fdr_client_t fdr); int fdr_poll_and_handle_message(fdr_client_t fdr); void *fdr_listener_thread(void *cdata); |