enh: Introduce iperf_set_test_logfile API function (#871)
To be able to set the test->outfile to a different file other than default if using libiperf API. Since logfile is now opened in iperf_parse_arguments() and this function may not be used if running iperf using API, define a dedicated function iperf_open_logfile() and move the opening of logfile into iperf_run_client() and iperf_run_server() to make sure logfile will be opened if iperf_parse_arguments() was not called.
Этот коммит содержится в:
родитель
fd46367fc4
Коммит
255a9c7110
@ -390,6 +390,12 @@ iperf_set_test_blksize(struct iperf_test *ipt, int blksize)
|
|||||||
ipt->settings->blksize = blksize;
|
ipt->settings->blksize = blksize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
iperf_set_test_logfile(struct iperf_test *ipt, char *logfile)
|
||||||
|
{
|
||||||
|
ipt->logfile = strdup(logfile);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
iperf_set_test_rate(struct iperf_test *ipt, uint64_t rate)
|
iperf_set_test_rate(struct iperf_test *ipt, uint64_t rate)
|
||||||
{
|
{
|
||||||
@ -1217,15 +1223,6 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set logging to a file if specified, otherwise use the default (stdout) */
|
|
||||||
if (test->logfile) {
|
|
||||||
test->outfile = fopen(test->logfile, "a+");
|
|
||||||
if (test->outfile == NULL) {
|
|
||||||
i_errno = IELOGFILE;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check flag / role compatibility. */
|
/* Check flag / role compatibility. */
|
||||||
if (test->role == 'c' && server_flag) {
|
if (test->role == 'c' && server_flag) {
|
||||||
i_errno = IESERVERONLY;
|
i_errno = IESERVERONLY;
|
||||||
@ -1350,6 +1347,20 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open the file specified by test->logfile and set test->outfile to its' FD.
|
||||||
|
*/
|
||||||
|
int iperf_open_logfile(struct iperf_test *test)
|
||||||
|
{
|
||||||
|
test->outfile = fopen(test->logfile, "a+");
|
||||||
|
if (test->outfile == NULL) {
|
||||||
|
i_errno = IELOGFILE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
iperf_set_send_state(struct iperf_test *test, signed char state)
|
iperf_set_send_state(struct iperf_test *test, signed char state)
|
||||||
{
|
{
|
||||||
|
@ -138,6 +138,7 @@ void iperf_set_test_reporter_interval( struct iperf_test* ipt, double reporter_i
|
|||||||
void iperf_set_test_stats_interval( struct iperf_test* ipt, double stats_interval );
|
void iperf_set_test_stats_interval( struct iperf_test* ipt, double stats_interval );
|
||||||
void iperf_set_test_state( struct iperf_test* ipt, signed char state );
|
void iperf_set_test_state( struct iperf_test* ipt, signed char state );
|
||||||
void iperf_set_test_blksize( struct iperf_test* ipt, int blksize );
|
void iperf_set_test_blksize( struct iperf_test* ipt, int blksize );
|
||||||
|
void iperf_set_test_logfile( struct iperf_test* ipt, char *logfile );
|
||||||
void iperf_set_test_rate( struct iperf_test* ipt, uint64_t rate );
|
void iperf_set_test_rate( struct iperf_test* ipt, uint64_t rate );
|
||||||
void iperf_set_test_pacing_timer( struct iperf_test* ipt, int pacing_timer );
|
void iperf_set_test_pacing_timer( struct iperf_test* ipt, int pacing_timer );
|
||||||
void iperf_set_test_bytes( struct iperf_test* ipt, uint64_t bytes );
|
void iperf_set_test_bytes( struct iperf_test* ipt, uint64_t bytes );
|
||||||
@ -267,6 +268,7 @@ int iperf_exchange_results(struct iperf_test *);
|
|||||||
int iperf_init_test(struct iperf_test *);
|
int iperf_init_test(struct iperf_test *);
|
||||||
int iperf_create_send_timers(struct iperf_test *);
|
int iperf_create_send_timers(struct iperf_test *);
|
||||||
int iperf_parse_arguments(struct iperf_test *, int, char **);
|
int iperf_parse_arguments(struct iperf_test *, int, char **);
|
||||||
|
int iperf_open_logfile(struct iperf_test *);
|
||||||
void iperf_reset_test(struct iperf_test *);
|
void iperf_reset_test(struct iperf_test *);
|
||||||
void iperf_reset_stats(struct iperf_test * test);
|
void iperf_reset_stats(struct iperf_test * test);
|
||||||
|
|
||||||
|
@ -454,6 +454,10 @@ iperf_run_client(struct iperf_test * test)
|
|||||||
struct timeval* timeout = NULL;
|
struct timeval* timeout = NULL;
|
||||||
struct iperf_stream *sp;
|
struct iperf_stream *sp;
|
||||||
|
|
||||||
|
if (test->logfile)
|
||||||
|
if (iperf_open_logfile(test) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (test->affinity != -1)
|
if (test->affinity != -1)
|
||||||
if (iperf_setaffinity(test, test->affinity) != 0)
|
if (iperf_setaffinity(test, test->affinity) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -398,6 +398,10 @@ iperf_run_server(struct iperf_test *test)
|
|||||||
struct timeval* timeout;
|
struct timeval* timeout;
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
|
if (test->logfile)
|
||||||
|
if (iperf_open_logfile(test) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (test->affinity != -1)
|
if (test->affinity != -1)
|
||||||
if (iperf_setaffinity(test, test->affinity) != 0)
|
if (iperf_setaffinity(test, test->affinity) != 0)
|
||||||
return -2;
|
return -2;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user