From 2e7e679eedb45b1ed7205d010bfb1b186a4b25c6 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 2 Mar 2016 00:53:32 -0500 Subject: [PATCH] simplify client_test shutdown and make it keep logging as saving resume data --- examples/client_test.cpp | 39 ++++----------------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 79e092155..e9e719023 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -2287,11 +2287,6 @@ int main(int argc, char* argv[]) } } - // keep track of the number of resume data - // alerts to wait for - int num_paused = 0; - int num_failed = 0; - ses.pause(); printf("saving resume data\n"); std::vector temp; @@ -2334,38 +2329,12 @@ int main(int argc, char* argv[]) for (std::vector::iterator i = alerts.begin() , end(alerts.end()); i != end; ++i) { - torrent_paused_alert* tp = alert_cast(*i); - if (tp) + if (!::handle_alert(ses, *i, files, non_files)) { - ++num_paused; - printf("\rleft: %d failed: %d pause: %d " - , num_outstanding_resume_data, num_failed, num_paused); - continue; + // if we didn't handle the alert, print it to the log + std::string event_string; + print_alert(*i, event_string); } - - if (alert_cast(*i)) - { - ++num_failed; - --num_outstanding_resume_data; - printf("\rleft: %d failed: %d pause: %d " - , num_outstanding_resume_data, num_failed, num_paused); - continue; - } - - save_resume_data_alert* rd = alert_cast(*i); - if (!rd) continue; - --num_outstanding_resume_data; - printf("\rleft: %d failed: %d pause: %d " - , num_outstanding_resume_data, num_failed, num_paused); - - if (!rd->resume_data) continue; - - torrent_handle h = rd->handle; - torrent_status st = h.status(torrent_handle::query_save_path); - std::vector out; - bencode(std::back_inserter(out), *rd->resume_data); - save_file(path_append(st.save_path, path_append(".resume" - , leaf_path(hash_to_filename[st.info_hash]) + ".resume")), out); } }