Timeout if UDP port isn't reachable
Add timeout to the UDP socket. Without it client would block infinitely if creating a control connection succeeds, but UDP packets are dropped by firewall.
This commit is contained in:
parent
72ac83e7f2
commit
9b9dd03096
@ -300,6 +300,7 @@ int
|
||||
iperf_udp_connect(struct iperf_test *test)
|
||||
{
|
||||
int s, buf, sz;
|
||||
struct timeval tv;
|
||||
|
||||
/* Create and bind our local socket. */
|
||||
if ((s = netdial(test->settings->domain, Pudp, test->bind_address, test->bind_port, test->server_hostname, test->server_port)) < 0) {
|
||||
@ -323,6 +324,11 @@ iperf_udp_connect(struct iperf_test *test)
|
||||
}
|
||||
}
|
||||
|
||||
/* 30 sec timeout for a case when there is a network problem. */
|
||||
tv.tv_sec = 30;
|
||||
tv.tv_usec = 0;
|
||||
setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv, sizeof(struct timeval));
|
||||
|
||||
/*
|
||||
* 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.
|
||||
|
Loading…
Reference in New Issue
Block a user