summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2016-06-26 18:30:40 +0200
committerGravatar Nikias Bassen2016-06-26 18:30:40 +0200
commita4df93a83cae154611377beb5254015dc95640b9 (patch)
tree883be3184d4174803a2deb04a9fda59b0df728ba
parent3e8651102df3a694c8e88a73b8d8d753f8d760c6 (diff)
downloadidevicerestore-a4df93a83cae154611377beb5254015dc95640b9.tar.gz
idevicerestore-a4df93a83cae154611377beb5254015dc95640b9.tar.bz2
fdr: Add fdr_disconnect() function to stop the FDR thread
-rw-r--r--src/fdr.c21
-rw-r--r--src/fdr.h1
2 files changed, 17 insertions, 5 deletions
diff --git a/src/fdr.c b/src/fdr.c
index 1468dc0..d7dc8d1 100644
--- a/src/fdr.c
+++ b/src/fdr.c
@@ -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)
diff --git a/src/fdr.h b/src/fdr.h
index 6139240..9822efc 100644
--- a/src/fdr.h
+++ b/src/fdr.h
@@ -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);