diff --git a/src/iperf.h b/src/iperf.h index 0707614bb..a614b4d33 100644 --- a/src/iperf.h +++ b/src/iperf.h @@ -183,6 +183,7 @@ struct iperf_stream int green_light; int buffer_fd; /* data to send, file descriptor */ char *buffer; /* data to send, mmapped */ + int pending_size; /* pending data to send */ int diskfile_fd; /* file to send, file descriptor */ int diskfile_left; /* remaining file data on disk */ diff --git a/src/iperf_api.c b/src/iperf_api.c index 07e044f92..d6997b69e 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -1629,7 +1629,8 @@ iperf_send(struct iperf_test *test, fd_set *write_setP) } streams_active = 1; test->bytes_sent += r; - ++test->blocks_sent; + if (!sp->pending_size) + ++test->blocks_sent; if (no_throttle_check) iperf_check_throttle(sp, &now); if (multisend > 1 && test->settings->bytes != 0 && test->bytes_sent >= test->settings->bytes) @@ -3927,6 +3928,7 @@ iperf_new_stream(struct iperf_test *test, int s, int sender) free(sp); return NULL; } + sp->pending_size = 0; /* Set socket */ sp->socket = s; diff --git a/src/iperf_tcp.c b/src/iperf_tcp.c index 47252d0e7..2dffaed1e 100644 --- a/src/iperf_tcp.c +++ b/src/iperf_tcp.c @@ -85,19 +85,24 @@ iperf_tcp_send(struct iperf_stream *sp) { int r; + if (!sp->pending_size) + sp->pending_size = sp->settings->blksize; + if (sp->test->zerocopy) - r = Nsendfile(sp->buffer_fd, sp->socket, sp->buffer, sp->settings->blksize); + r = Nsendfile(sp->buffer_fd, sp->socket, sp->buffer, sp->pending_size); else - r = Nwrite(sp->socket, sp->buffer, sp->settings->blksize, Ptcp); + r = Nwrite(sp->socket, sp->buffer, sp->pending_size, Ptcp); if (r < 0) return r; + sp->pending_size -= r; sp->result->bytes_sent += r; sp->result->bytes_sent_this_interval += r; if (sp->test->debug) - printf("sent %d bytes of %d, total %" PRIu64 "\n", r, sp->settings->blksize, sp->result->bytes_sent); + printf("sent %d bytes of %d, pending %d, total %" PRIu64 "\n", + r, sp->settings->blksize, sp->pending_size, sp->result->bytes_sent); return r; }