From 57a6e3ac29202ea8be06f972c8783d701a076ecb Mon Sep 17 00:00:00 2001 From: Vulpine05 Date: Sun, 3 Jul 2022 14:33:47 -0500 Subject: [PATCH] Added estimated transfer time remaining --- client/pers_file_xfer.cpp | 22 +++++++++++++++++++++- client/pers_file_xfer.h | 3 ++- lib/gui_rpc_client.h | 3 ++- lib/gui_rpc_client_ops.cpp | 6 ++++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/client/pers_file_xfer.cpp b/client/pers_file_xfer.cpp index 211828d076..b9710d5ff0 100644 --- a/client/pers_file_xfer.cpp +++ b/client/pers_file_xfer.cpp @@ -1,6 +1,6 @@ // This file is part of BOINC. // http://boinc.berkeley.edu -// Copyright (C) 2008 University of California +// Copyright (C) 2022 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License @@ -446,11 +446,13 @@ int PERS_FILE_XFER::write(MIOFILE& fout) { if (fxp) { fout.printf( " \n" + " %f\n" " %f\n" " %f\n" " %f\n" " %s\n" " \n", + estimated_xfer_time_remaining(), fxp->bytes_xferred, fxp->file_offset, fxp->xfer_speed, @@ -476,6 +478,24 @@ void PERS_FILE_XFER::suspend() { fip->upload_offset = -1; } +// Determines the amount of time for a pfx to complete. Returns time in seconds. +// +double PERS_FILE_XFER::estimated_xfer_time_remaining() { + // The estimated transfer duration will be set to 0 (or, '---' as displayed in the Manager) in three conditions: + // 1. The pfx is complete. + // 2. The file has not started transferring. + // 3. If the transfer speed is 0. This is for conditions when xfer_speed has not been calculated yet + // (either from the transfer returning from suspension or the BOINC starting up). + if (pers_xfer_done || fxp==0 || fxp->xfer_speed==0) { + return 0; + } + double bytes_remaining = (fip->nbytes - last_bytes_xferred); + double est_duration = bytes_remaining / fxp->xfer_speed; + if (est_duration <= 0) est_duration = 1; + return est_duration; +} + + PERS_FILE_XFER_SET::PERS_FILE_XFER_SET(FILE_XFER_SET* p) { file_xfers = p; } diff --git a/client/pers_file_xfer.h b/client/pers_file_xfer.h index 64902d1740..78035f354c 100644 --- a/client/pers_file_xfer.h +++ b/client/pers_file_xfer.h @@ -1,6 +1,6 @@ // This file is part of BOINC. // http://boinc.berkeley.edu -// Copyright (C) 2008 University of California +// Copyright (C) 2022 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License @@ -115,6 +115,7 @@ public: int create_xfer(); int start_xfer(); void suspend(); + double estimated_xfer_time_remaining(); }; class PERS_FILE_XFER_SET { diff --git a/lib/gui_rpc_client.h b/lib/gui_rpc_client.h index 4bace5fb20..990b3c1bb6 100644 --- a/lib/gui_rpc_client.h +++ b/lib/gui_rpc_client.h @@ -1,6 +1,6 @@ // This file is part of BOINC. // https://boinc.berkeley.edu -// Copyright (C) 2020 University of California +// Copyright (C) 2022 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License @@ -329,6 +329,7 @@ struct FILE_TRANSFER { double next_request_time; int status; double time_so_far; + double estimated_xfer_time_remaining; double bytes_xferred; double file_offset; double xfer_speed; diff --git a/lib/gui_rpc_client_ops.cpp b/lib/gui_rpc_client_ops.cpp index b804ee40ad..ef84f8f48e 100644 --- a/lib/gui_rpc_client_ops.cpp +++ b/lib/gui_rpc_client_ops.cpp @@ -1,6 +1,6 @@ // This file is part of BOINC. // https://boinc.berkeley.edu -// Copyright (C) 2020 University of California +// Copyright (C) 2022 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License @@ -784,6 +784,7 @@ int FILE_TRANSFER::parse(XML_PARSER& xp) { if (xp.parse_double("next_request_time", next_request_time)) continue; if (xp.parse_int("status", status)) continue; if (xp.parse_double("time_so_far", time_so_far)) continue; + if (xp.parse_double("estimated_xfer_time_remaining", estimated_xfer_time_remaining)) continue; if (xp.parse_double("last_bytes_xferred", bytes_xferred)) continue; if (xp.parse_double("file_offset", file_offset)) continue; if (xp.parse_double("xfer_speed", xfer_speed)) continue; @@ -809,6 +810,7 @@ void FILE_TRANSFER::clear() { next_request_time = 0; status = 0; time_so_far = 0; + estimated_xfer_time_remaining = 0; bytes_xferred = 0; file_offset = 0; xfer_speed = 0; @@ -1965,7 +1967,7 @@ int RPC_CLIENT::run_benchmarks() { // start or stop a graphics app on behalf of the screensaver. // (needed for Mac OS X 10.15+) // -//