Skip to content

Commit

Permalink
fix tcp option -k bug when socket write return EAGAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
hyswtj committed Dec 14, 2020
1 parent d2a68e0 commit 95ce16b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/iperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
4 changes: 3 additions & 1 deletion src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions src/iperf_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 95ce16b

Please sign in to comment.