Add one-off mode, where the server serves exactly one request.
Primarily useful for bwctl integration, this is enabled with the -1 and/or --one-off flags. Fixes #230, based on a patch by @i2aaron. Signed-off-by: Bruce A. Mah <bmah@es.net>
Этот коммит содержится в:
родитель
4450b1b86d
Коммит
dba611dbe4
@ -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 */
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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 <host> run in client mode, connecting to <host>\n"
|
||||
#if defined(HAVE_SCTP)
|
||||
|
@ -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;
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user