From 08a2de459beb605fa3606b8d9f0ffba6028d7dee Mon Sep 17 00:00:00 2001 From: QuaSoft Date: Sun, 6 Mar 2016 16:47:02 +0200 Subject: [PATCH] Add command line option `--forceflush` to allow user to request flushing of output at the end of each interval. Fixes #299 --- docs/invoking.rst | 4 ++++ src/iperf.h | 1 + src/iperf3.1 | 4 ++++ src/iperf_api.c | 6 +++++- src/iperf_api.h | 1 + src/iperf_locale.c | 1 + 6 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/invoking.rst b/docs/invoking.rst index 6048303..2197409 100644 --- a/docs/invoking.rst +++ b/docs/invoking.rst @@ -82,6 +82,10 @@ the executable. ‐‐logfile file send output to a log file. + --forceflush + force flushing output at every interval. Used to avoid buffering when sending + output to pipe. + ‐d, ‐‐debug emit debugging output. Primarily (perhaps exclusively) of use to developers. diff --git a/src/iperf.h b/src/iperf.h index ca0a4e2..426565d 100755 --- a/src/iperf.h +++ b/src/iperf.h @@ -236,6 +236,7 @@ struct iperf_test int debug; /* -d option - enable debug */ int get_server_output; /* --get-server-output */ int udp_counters_64bit; /* --use-64-bit-udp-counters */ + int forceflush; /* --forceflush - flushing output at every interval */ int multisend; diff --git a/src/iperf3.1 b/src/iperf3.1 index 272a6f7..5bc3736 100644 --- a/src/iperf3.1 +++ b/src/iperf3.1 @@ -58,6 +58,10 @@ output in JSON format .BR --logfile " \fIfile\fR" send output to a log file. .TP +.BR --forceflush " " +force flushing output at every interval. +Used to avoid buffering when sending output to pipe. +.TP .BR -d ", " --debug " " emit debugging output. Primarily (perhaps exclusively) of use to developers. diff --git a/src/iperf_api.c b/src/iperf_api.c index d7c5749..b374690 100755 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -653,6 +653,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) #endif {"pidfile", required_argument, NULL, 'I'}, {"logfile", required_argument, NULL, OPT_LOGFILE}, + {"forceflush", no_argument, NULL, OPT_FORCEFLUSH}, {"get-server-output", no_argument, NULL, OPT_GET_SERVER_OUTPUT}, {"udp-counters-64bit", no_argument, NULL, OPT_UDP_COUNTERS_64BIT}, {"debug", no_argument, NULL, 'd'}, @@ -927,6 +928,9 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) case OPT_LOGFILE: test->logfile = strdup(optarg); break; + case OPT_FORCEFLUSH: + test->forceflush = 1; + break; case OPT_GET_SERVER_OUTPUT: test->get_server_output = 1; client_flag = 1; @@ -2582,7 +2586,7 @@ print_interval_results(struct iperf_test *test, struct iperf_stream *sp, cJSON * } } - if (test->logfile) + if (test->logfile || test->forceflush) iflush(test); } diff --git a/src/iperf_api.h b/src/iperf_api.h index d16cb8a..5a7d40a 100755 --- a/src/iperf_api.h +++ b/src/iperf_api.h @@ -50,6 +50,7 @@ struct iperf_stream; #define OPT_UDP_COUNTERS_64BIT 4 #define OPT_CLIENT_PORT 5 #define OPT_NUMSTREAMS 6 +#define OPT_FORCEFLUSH 7 /* states */ #define TEST_START 1 diff --git a/src/iperf_locale.c b/src/iperf_locale.c index ee3a74a..4404059 100644 --- a/src/iperf_locale.c +++ b/src/iperf_locale.c @@ -108,6 +108,7 @@ const char usage_longstr[] = "Usage: iperf [-s|-c host] [options]\n" " -V, --verbose more detailed output\n" " -J, --json output in JSON format\n" " --logfile f send output to a log file\n" + " --forceflush force flushing output at every interval\n" " -d, --debug emit debugging output\n" " -v, --version show version information and quit\n" " -h, --help show this message and quit\n"