diff options
| author | 2013-09-19 05:22:16 +0200 | |
|---|---|---|
| committer | 2013-09-19 05:22:16 +0200 | |
| commit | 52b32cdd8c58b42379b367fe5e4f01db730acf3b (patch) | |
| tree | 101d2c94f4cc94484f17af24097e634fad97e64d /src | |
| parent | a84e717eecf2dda8221a8aa8569148c01f2505b0 (diff) | |
| download | libimobiledevice-52b32cdd8c58b42379b367fe5e4f01db730acf3b.tar.gz libimobiledevice-52b32cdd8c58b42379b367fe5e4f01db730acf3b.tar.bz2 | |
notification_proxy: handle error conditions in notification polling thread
Diffstat (limited to 'src')
| -rw-r--r-- | src/notification_proxy.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/notification_proxy.c b/src/notification_proxy.c index 88ff72b..3f48601 100644 --- a/src/notification_proxy.c +++ b/src/notification_proxy.c | |||
| @@ -309,11 +309,15 @@ static int np_get_notification(np_client_t client, char **notification) | |||
| 309 | 309 | ||
| 310 | np_lock(client); | 310 | np_lock(client); |
| 311 | 311 | ||
| 312 | property_list_service_receive_plist_with_timeout(client->parent, &dict, 500); | 312 | property_list_service_error_t perr = property_list_service_receive_plist_with_timeout(client->parent, &dict, 500); |
| 313 | if (!dict) { | 313 | if (perr == PROPERTY_LIST_SERVICE_E_TIMEOUT) { |
| 314 | debug_info("NotificationProxy: no notification received!"); | 314 | debug_info("NotificationProxy: no notification received!"); |
| 315 | res = 0; | 315 | res = 0; |
| 316 | } else { | 316 | } else if (perr != PROPERTY_LIST_SERVICE_E_SUCCESS) { |
| 317 | debug_info("NotificationProxy: error %d occured!", perr); | ||
| 318 | res = perr; | ||
| 319 | } | ||
| 320 | if (dict) { | ||
| 317 | char *cmd_value = NULL; | 321 | char *cmd_value = NULL; |
| 318 | plist_t cmd_value_node = plist_dict_get_item(dict, "Command"); | 322 | plist_t cmd_value_node = plist_dict_get_item(dict, "Command"); |
| 319 | 323 | ||
| @@ -368,7 +372,10 @@ void* np_notifier( void* arg ) | |||
| 368 | 372 | ||
| 369 | debug_info("starting callback."); | 373 | debug_info("starting callback."); |
| 370 | while (npt->client->parent) { | 374 | while (npt->client->parent) { |
| 371 | np_get_notification(npt->client, ¬ification); | 375 | if (np_get_notification(npt->client, ¬ification) < 0) { |
| 376 | npt->cbfunc("", npt->user_data); | ||
| 377 | break; | ||
| 378 | } | ||
| 372 | if (notification) { | 379 | if (notification) { |
| 373 | npt->cbfunc(notification, npt->user_data); | 380 | npt->cbfunc(notification, npt->user_data); |
| 374 | free(notification); | 381 | free(notification); |
| @@ -388,6 +395,9 @@ void* np_notifier( void* arg ) | |||
| 388 | * be called when a notification has been received. | 395 | * be called when a notification has been received. |
| 389 | * It will start a thread that polls for notifications and calls the callback | 396 | * It will start a thread that polls for notifications and calls the callback |
| 390 | * function if a notification has been received. | 397 | * function if a notification has been received. |
| 398 | * In case of an error condition when polling for notifications - e.g. device | ||
| 399 | * disconnect - the thread will call the callback function with an empty | ||
| 400 | * notification "" and terminate itself. | ||
| 391 | * | 401 | * |
| 392 | * @param client the NP client | 402 | * @param client the NP client |
| 393 | * @param notify_cb pointer to a callback function or NULL to de-register a | 403 | * @param notify_cb pointer to a callback function or NULL to de-register a |
