From: Shin-ya Koga <
shiny...@atmark-techno.com>
Mirror suricatta (-u)'s --max-download-speed option for downloader (-d),
users sometime need to limit download speed on bad connections.
Note ustrtoull parses K/M/G suffixes for us.
Signed-off-by: Shin-ya Koga <
shiny...@atmark-techno.com>
corelib/downloader.c | 11 +++++++++--
doc/source/swupdate.rst | 8 ++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/corelib/downloader.c b/corelib/downloader.c
index a3d74e60f274..04dea8b935ad 100644
--- a/corelib/downloader.c
+++ b/corelib/downloader.c
@@ -36,6 +36,7 @@ static struct option long_options[] = {
{"retrywait", required_argument, NULL, 'w'},
{"timeout", required_argument, NULL, 't'},
{"authentication", required_argument, NULL, 'a'},
+ {"max-download-speed", required_argument, NULL, 'n'},
{NULL, 0, NULL, 0}};
static channel_data_t channel_options = {
@@ -202,7 +203,9 @@ void download_print_help(void)
"\t is broken (0 means indefinitely retries) (default: %d)\n"
"\t -w, --retrywait timeout to wait before retrying retries (default: %d)\n"
"\t -t, --timeout timeout to check if a connection is lost (default: %d)\n"
- "\t -a, --authentication authentication information as username:password\n",
+ "\t -a, --authentication authentication information as username:password\n"
+ "\t -n, --max-download-speed <limit> Set download speed limit.\n"
+ "\t Example: -n 100k; -n 1M; -n 100; -n 1G (default: no limit)\n",
DL_DEFAULT_RETRIES, DL_LOWSPEED_TIME, CHANNEL_DEFAULT_RESUME_DELAY);
}
@@ -220,7 +223,7 @@ int start_download_server(const char *fname, int argc, char *argv[])
/* reset to optind=1 to parse download's argument vector */
optind = 1;
int choice = 0;
- while ((choice = getopt_long(argc, argv, "t:u:w:r:a:",
+ while ((choice = getopt_long(argc, argv, "t:u:w:r:a:n:",
long_options, NULL)) != -1) {
switch (choice) {
case 't':
@@ -238,6 +241,10 @@ int start_download_server(const char *fname, int argc, char *argv[])
case 'r':
channel_options.retries = strtoul(optarg, NULL, 10);
break;
+ case 'n':
+ channel_options.max_download_speed =
+ (unsigned int)ustrtoull(optarg, NULL, 10);
+ break;
case '?':
default:
return -EINVAL;
diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst
index ff00ca02a144..489604c73a2b 100644
--- a/doc/source/swupdate.rst
+++ b/doc/source/swupdate.rst
@@ -605,6 +605,14 @@ Mandatory arguments are marked with '\*':
+----------------+----------+--------------------------------------------+
| -a <usr:pwd> | string | Send user and password for Basic Auth |
+----------------+----------+--------------------------------------------+
+| -n <value> | string | Maximum download speed to be used. |
+| | | Value be specified in kB/s, B/s, MB/s |
+| | | or GB/s. Examples: |
+| | | -n 100k : Set limit to 100 kB/s. |
+| | | -n 500 : Set limit to 500 B/s. |
+| | | -n 2M : Set limit to 1 M/s. |
+| | | -n 1G : Set limit to 1 G/s. |
++----------------+----------+--------------------------------------------+
Suricatta command line parameters
.................................
--
2.39.2