Skip to content

Commit

Permalink
Adding -K (sender file seek) and -a (receiver append to file)
Browse files Browse the repository at this point in the history
commit df6ca5c
Author: Hamid Anvari <hr.anvari@gmail.com>
Date:   Mon Mar 1 19:57:56 2021 -0700

    adding -a switch to allow receiving appending to file in -F mode

    # Conflicts: (Resolved)
    #	src/iperf.h
    #	src/iperf_api.c

commit db2a13c
Author: Hamid Anvari <hr.anvari@gmail.com>
Date:   Fri Feb 19 15:59:59 2021 -0700

    Adding -K switch along with -F to allow seek in file

    # Conflicts: (Resolved)
    #	src/iperf.h
    #	src/iperf_api.c
  • Loading branch information
hanvari committed Jul 3, 2021
1 parent 6af2ccc commit e3b3440
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/iperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ struct iperf_test
int duration; /* total duration of test (-t flag) */
char *diskfile_name; /* -F option */
int reliable_receive_in_full; /* -r option. For reciever only. */
int diskfile_seek; /* -K option */
int diskfile_append; /* -a option */
int affinity, server_affinity; /* -A option */
#if defined(HAVE_CPUSET_SETAFFINITY)
cpuset_t cpumask;
Expand Down
27 changes: 24 additions & 3 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,8 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
{"omit", required_argument, NULL, 'O'},
{"file", required_argument, NULL, 'F'},
{"reliable", required_argument, NULL, 'r'},
{"fileseek", required_argument, NULL, 'K'},
{"fileappend", required_argument, NULL, 'a'},
{"repeating-payload", no_argument, NULL, OPT_REPEATING_PAYLOAD},
{"timestamps", optional_argument, NULL, OPT_TIMESTAMPS},
#if defined(HAVE_CPU_AFFINITY)
Expand Down Expand Up @@ -1030,7 +1032,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
char *client_username = NULL, *client_rsa_public_key = NULL, *server_rsa_private_key = NULL;
#endif /* HAVE_SSL */

while ((flag = getopt_long(argc, argv, "p:f:i:D1VJvsc:ub:t:n:k:l:P:Rw:B:M:N46S:L:ZO:F:rA:T:C:dI:hX:", 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:arK:A:T:C:dI:hX:", longopts, NULL)) != -1) {
switch (flag) {
case 'p':
portno = atoi(optarg);
Expand Down Expand Up @@ -1332,6 +1334,12 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
case 'r':
test->reliable_receive_in_full = 1;
break;
case 'K': // seek in file
test->diskfile_seek = atoi(optarg);
break;
case 'a': // append to file, not overwriting
test->diskfile_append = 1;
break;
case OPT_IDLE_TIMEOUT:
test->settings->idle_timeout = atoi(optarg);
if (test->settings->idle_timeout < 1 || test->settings->idle_timeout > MAX_TIME) {
Expand Down Expand Up @@ -1576,6 +1584,8 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
struct stat st;
stat(test->diskfile_name, &st);
iperf_size_t file_bytes = st.st_size;
// if we are seeking in file, decrease file size by seek value
file_bytes -= test->diskfile_seek;
test->settings->bytes = file_bytes;
if (test->debug)
printf("End condition set to file-size: %d bytes\n", test->settings->bytes);
Expand Down Expand Up @@ -2640,6 +2650,8 @@ iperf_defaults(struct iperf_test *testp)
testp->duration = DURATION;
testp->diskfile_name = (char*) 0;
testp->reliable_receive_in_full = 0;
testp->diskfile_seek = 0;
testp->diskfile_append = 0;
testp->affinity = -1;
testp->server_affinity = -1;
TAILQ_INIT(&testp->xbind_addrs);
Expand Down Expand Up @@ -4080,15 +4092,24 @@ iperf_new_stream(struct iperf_test *test, int s, int sender)
sp->rcv = test->protocol->recv;

if (test->diskfile_name != (char*) 0) {
sp->diskfile_fd = open(test->diskfile_name, sender ? O_RDONLY : (O_WRONLY|O_CREAT|O_TRUNC), S_IRUSR|S_IWUSR);
sp->diskfile_fd = open(test->diskfile_name, sender ? O_RDONLY : (O_WRONLY|O_CREAT|(sp->test->diskfile_append ? O_APPEND : O_TRUNC)), S_IRUSR|S_IWUSR);
if (sp->diskfile_fd == -1) {
i_errno = IEFILE;
munmap(sp->buffer, sp->test->settings->blksize);
free(sp->result);
free(sp);
return NULL;
}
sp->snd2 = sp->snd;
// Seek to file location if asked for
if(test->diskfile_seek > 0){
if(lseek(sp->diskfile_fd, test->diskfile_seek,SEEK_SET) < 0){
// Error !
i_errno = IEFILE;
return NULL;
}
}

sp->snd2 = sp->snd;
sp->snd = diskfile_send;
sp->rcv2 = sp->rcv;
sp->rcv = diskfile_recv;
Expand Down

0 comments on commit e3b3440

Please sign in to comment.