diff --git a/src/iperf.h b/src/iperf.h index 15e7ddb..8a9e941 100644 --- a/src/iperf.h +++ b/src/iperf.h @@ -217,6 +217,7 @@ struct iperf_test /* boolean variables for Options */ int daemon; /* -D option */ + int one_off; /* -1 option */ int no_delay; /* -N option */ int reverse; /* -R option */ int verbose; /* -V option - verbose mode */ diff --git a/src/iperf3.1 b/src/iperf3.1 index a7e67e6..5d14345 100644 --- a/src/iperf3.1 +++ b/src/iperf3.1 @@ -78,6 +78,9 @@ run the server in background as a daemon .TP .BR -I ", " --pidfile " \fIfile\fR" write a file with the process ID, most useful when running as a daemon. +.TP +.BR -1 ", " --one-off +handle one client connection, then exit. .SH "CLIENT SPECIFIC OPTIONS" .TP diff --git a/src/iperf_api.c b/src/iperf_api.c index 55660c9..2c3dccb 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -258,6 +258,12 @@ iperf_get_test_udp_counters_64bit(struct iperf_test *ipt) return ipt->udp_counters_64bit; } +int +iperf_get_test_one_off(struct iperf_test *ipt) +{ + return ipt->one_off; +} + /************** Setter routines for some fields inside iperf_test *************/ void @@ -417,6 +423,12 @@ iperf_set_test_udp_counters_64bit(struct iperf_test *ipt, int udp_counters_64bit ipt->udp_counters_64bit = udp_counters_64bit; } +void +iperf_set_test_one_off(struct iperf_test *ipt, int one_off) +{ + ipt->one_off = one_off; +} + /********************** Get/set test protocol structure ***********************/ struct protocol * @@ -586,6 +598,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) {"format", required_argument, NULL, 'f'}, {"interval", required_argument, NULL, 'i'}, {"daemon", no_argument, NULL, 'D'}, + {"one-off", no_argument, NULL, '1'}, {"verbose", no_argument, NULL, 'V'}, {"json", no_argument, NULL, 'J'}, {"version", no_argument, NULL, 'v'}, @@ -642,7 +655,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) blksize = 0; server_flag = client_flag = rate_flag = duration_flag = 0; - while ((flag = getopt_long(argc, argv, "p:f:i:DVJvsc:ub:t:n:k:l:P:Rw:B:M:N46S:L:ZO:F:A:T:C:dI:h", longopts, NULL)) != -1) { + while ((flag = getopt_long(argc, argv, "p:f:i:D1VJvsc:ub:t:n:k:l:P:Rw:B:M:N46S:L:ZO:F:A:T:C:dI:h", longopts, NULL)) != -1) { switch (flag) { case 'p': test->server_port = atoi(optarg); @@ -663,6 +676,10 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) test->daemon = 1; server_flag = 1; break; + case '1': + test->one_off = 1; + server_flag = 1; + break; case 'V': test->verbose = 1; break; diff --git a/src/iperf_api.h b/src/iperf_api.h index d958581..75162b7 100644 --- a/src/iperf_api.h +++ b/src/iperf_api.h @@ -93,6 +93,7 @@ int iperf_get_test_zerocopy( struct iperf_test* ipt ); int iperf_get_test_get_server_output( struct iperf_test* ipt ); char* iperf_get_test_bind_address ( struct iperf_test* ipt ); int iperf_get_test_udp_counters_64bit( struct iperf_test* ipt ); +int iperf_get_test_one_off( struct iperf_test* ipt ); /* Setter routines for some fields inside iperf_test. */ void iperf_set_verbose( struct iperf_test* ipt, int verbose ); @@ -117,6 +118,7 @@ void iperf_set_test_zerocopy( struct iperf_test* ipt, int zerocopy ); void iperf_set_test_get_server_output( struct iperf_test* ipt, int get_server_output ); void iperf_set_test_bind_address( struct iperf_test* ipt, char *bind_address ); void iperf_set_test_udp_counters_64bit( struct iperf_test* ipt, int udp_counters_64bit ); +void iperf_set_test_one_off( struct iperf_test* ipt, int one_off ); /** * exchange_parameters - handles the param_Exchange part for client diff --git a/src/iperf_locale.c b/src/iperf_locale.c index 354906f..df63922 100644 --- a/src/iperf_locale.c +++ b/src/iperf_locale.c @@ -115,6 +115,7 @@ const char usage_longstr[] = "Usage: iperf [-s|-c host] [options]\n" " -s, --server run in server mode\n" " -D, --daemon run the server as a daemon\n" " -I, --pidfile file write PID file\n" + " -1, --one-off handle one client connection then exit\n" "Client specific:\n" " -c, --client run in client mode, connecting to \n" #if defined(HAVE_SCTP) diff --git a/src/main.c b/src/main.c index 7879557..c713858 100644 --- a/src/main.c +++ b/src/main.c @@ -148,6 +148,8 @@ run(struct iperf_test *test) } else consecutive_errors = 0; iperf_reset_test(test); + if (iperf_get_test_one_off(test)) + break; } iperf_delete_pidfile(test); break;