From cbacc1d670afa463f76ca60fbc57e438e4e91298 Mon Sep 17 00:00:00 2001 From: "Bruce A. Mah" Date: Wed, 23 Apr 2014 15:01:27 -0700 Subject: [PATCH] Only set sockets to non-blocking mode on the sending side of the transfer. Note that the sender can either be the client or the server depending on whether --reverse is used. This fixes some problems with UDP transfers getting severely confused and (wrongly) complaining about packets arriving out of order. Related to issue #125. --- src/iperf_client_api.c | 18 ++++++++++++------ src/iperf_server_api.c | 5 ++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c index 0976b07..866d446 100644 --- a/src/iperf_client_api.c +++ b/src/iperf_client_api.c @@ -381,9 +381,12 @@ iperf_run_client(struct iperf_test * test) if (startup) { startup = 0; - SLIST_FOREACH(sp, &test->streams, streams) { - setnonblocking(sp->socket, 1); - } + // If the client is sending (normal mode) then set nonblocking sockets + if (!test->reverse) { + SLIST_FOREACH(sp, &test->streams, streams) { + setnonblocking(sp->socket, 1); + } + } } if (test->reverse) { @@ -406,9 +409,12 @@ iperf_run_client(struct iperf_test * test) (test->settings->bytes != 0 && test->bytes_sent >= test->settings->bytes) || (test->settings->blocks != 0 && test->blocks_sent >= test->settings->blocks))) { - SLIST_FOREACH(sp, &test->streams, streams) { - setnonblocking(sp->socket, 0); - } + // If the client is sending (normal mode) then undo nonblocking sockets + if (!test->reverse) { + SLIST_FOREACH(sp, &test->streams, streams) { + setnonblocking(sp->socket, 0); + } + } /* Yes, done! Send TEST_END. */ test->done = 1; diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index e522ca6..83a7cb1 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -516,7 +516,10 @@ iperf_run_server(struct iperf_test *test) FD_SET(s, &test->read_set); if (s > test->max_fd) test->max_fd = s; - setnonblocking(s, 1); + // If the server is sending (reverse mode) then set nonblocking sockets + if (test->reverse) { + setnonblocking(s, 1); + } streams_accepted++; if (test->on_new_stream)