Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iperf_udp: implement UDP connect retry mechanism #1144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 42 additions & 18 deletions src/iperf_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,26 +556,50 @@ iperf_udp_connect(struct iperf_test *test)
setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv, sizeof(struct timeval));
#endif

/*
* Write a datagram to the UDP stream to let the server know we're here.
* The server learns our address by obtaining its peer's address.
*/
buf = 123456789; /* this can be pretty much anything */
if (write(s, &buf, sizeof(buf)) < 0) {
// XXX: Should this be changed to IESTREAMCONNECT?
i_errno = IESTREAMWRITE;
return -1;
}
for (int i=0; i<5; i++){
/* retry the connection setup for up to 5 times */

/*
* Write a datagram to the UDP stream to let the server know we're here.
* The server learns our address by obtaining its peer's address.
*/
buf = 123456789; /* this can be pretty much anything */
if (write(s, &buf, sizeof(buf)) < 0) {
// XXX: Should this be changed to IESTREAMCONNECT?
i_errno = IESTREAMWRITE;
return -1;
}

/*
* Wait until the server replies back to us.
*/
if ((sz = recv(s, &buf, sizeof(buf), 0)) < 0) {
i_errno = IESTREAMREAD;
return -1;
}
int result;
fd_set read_set;
struct timeval timeout;

return s;
timeout.tv_sec = 1;
timeout.tv_usec = 0;

memcpy(&read_set, &test->read_set, sizeof(fd_set));
result = select(test->max_fd + 1, &read_set, NULL, NULL, &timeout);
if (result < 0 && errno != EINTR) {
i_errno = IESELECT;
return -1;
} else if (result > 0) {
/*
* Wait until the server replies back to us.
*/
if ((sz = recv(s, &buf, sizeof(buf), 0)) < 0) {
i_errno = IESTREAMREAD;
return -1;
} else {
return s;
}
} else {
if (test->debug)
fprintf(stderr, "Retrying udp connection in 1s.");
sleep(1);
}
}
i_errno = IESTREAMREAD;
return -1;
}


Expand Down