From 6af2ccc457a42b7b00c8c4afe7288edf75c1104c Mon Sep 17 00:00:00 2001
From: Hamid Anvari
Date: Tue, 2 Feb 2021 02:04:07 -0700
Subject: [PATCH] Auto adjustment of test-end condition for file-transfer
In file transfer mode (-F), if no test-end condition is set,
(bytes, blocks, duration), it will automatically adjsut it to
file size (in bytes).
---
src/iperf_api.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/iperf_api.c b/src/iperf_api.c
index 356e38113..a9d36c977 100644
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -1564,6 +1564,23 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
if (!rate_flag)
test->settings->rate = test->protocol->id == Pudp ? UDP_RATE : 0;
+ /* if no bytes or blocks specified, nor a duration_flag, and we have -F,
+ ** get the file-size as the bytes count to be transferred
+ */
+ if (test->settings->bytes == 0 &&
+ test->settings->blocks == 0 &&
+ ! duration_flag &&
+ test->diskfile_name != (char*) 0 &&
+ test->role == 'c'
+ ){
+ struct stat st;
+ stat(test->diskfile_name, &st);
+ iperf_size_t file_bytes = st.st_size;
+ test->settings->bytes = file_bytes;
+ if (test->debug)
+ printf("End condition set to file-size: %d bytes\n", test->settings->bytes);
+ }
+
if ((test->settings->bytes != 0 || test->settings->blocks != 0) && ! duration_flag)
test->duration = 0;