Make UDP packet reception work right with non-blocking sockets and enable.

We need this to permit a UDP receiving iperf3 server to listen on its
control channel.

The fix for non-blocking sockets basically makes sure that if we do a
read on a non-blocking sockets, but there's no data, the UDP processing
code does *not* try to do the normal protocol packet processing on the
non-existent packet.

This is part of an ongoing fix for issue #212 but also should have been
a part of the fix for issue #125.
This commit is contained in:
Bruce A. Mah 2014-10-13 04:28:58 -07:00
parent 78033c4359
commit 8694d1db0d
2 changed files with 14 additions and 3 deletions

View File

@ -534,8 +534,14 @@ iperf_run_server(struct iperf_test *test)
FD_SET(s, &test->read_set);
if (s > test->max_fd) test->max_fd = s;
// If the protocol isn't UDP, set nonblocking sockets
if (test->protocol->id != Pudp) {
/*
* If the protocol isn't UDP, or even if it is but
* we're the receiver, set nonblocking sockets.
* We need this to allow a server receiver to
* maintain interactivity with the control channel.
*/
if (test->protocol->id != Pudp ||
!test->sender) {
setnonblocking(s, 1);
}

View File

@ -63,7 +63,12 @@ iperf_udp_recv(struct iperf_stream *sp)
r = Nread(sp->socket, sp->buffer, size, Pudp);
if (r < 0)
/*
* If we got an error in the read, or if we didn't read anything
* because the underlying read(2) got a EAGAIN, then skip packet
* processing.
*/
if (r <= 0)
return r;
sp->result->bytes_received += r;