Skip to content

Commit

Permalink
Merge pull request #1619 from maks-mishin/master
Browse files Browse the repository at this point in the history
Add error handling for close socket
  • Loading branch information
bmah888 authored May 24, 2024
2 parents 7a082f5 + f5c253e commit 8f5a87e
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ int
iperf_accept(struct iperf_test *test)
{
int s;
int ret = -1;
signed char rbuf = ACCESS_DENIED;
socklen_t len;
struct sockaddr_storage addr;

len = sizeof(addr);
if ((s = accept(test->listener, (struct sockaddr *) &addr, &len)) < 0) {
i_errno = IEACCEPT;
return -1;
return ret;
}

if (test->ctrl_sck == -1) {
Expand All @@ -152,15 +153,15 @@ iperf_accept(struct iperf_test *test)
int flag = 1;
if (setsockopt(test->ctrl_sck, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int))) {
i_errno = IESETNODELAY;
return -1;
goto error_handling;
}

#if defined(HAVE_TCP_USER_TIMEOUT)
int opt;
if ((opt = test->settings->snd_timeout)) {
if (setsockopt(s, IPPROTO_TCP, TCP_USER_TIMEOUT, &opt, sizeof(opt)) < 0) {
i_errno = IESETUSERTIMEOUT;
return -1;
goto error_handling;
}
}
#endif /* HAVE_TCP_USER_TIMEOUT */
Expand All @@ -172,18 +173,18 @@ iperf_accept(struct iperf_test *test)
* (i.e. timed out).
*/
i_errno = IERECVCOOKIE;
return -1;
goto error_handling;
}
FD_SET(test->ctrl_sck, &test->read_set);
if (test->ctrl_sck > test->max_fd) test->max_fd = test->ctrl_sck;
FD_SET(test->ctrl_sck, &test->read_set);
if (test->ctrl_sck > test->max_fd) test->max_fd = test->ctrl_sck;

if (iperf_set_send_state(test, PARAM_EXCHANGE) != 0)
return -1;
if (iperf_exchange_parameters(test) < 0)
return -1;
if (test->server_affinity != -1)
if (iperf_setaffinity(test, test->server_affinity) != 0)
return -1;
if (iperf_set_send_state(test, PARAM_EXCHANGE) != 0)
goto error_handling;
if (iperf_exchange_parameters(test) < 0)
goto error_handling;
if (test->server_affinity != -1)
if (iperf_setaffinity(test, test->server_affinity) != 0)
goto error_handling;
if (test->on_connect)
test->on_connect(test);
} else {
Expand All @@ -202,8 +203,10 @@ iperf_accept(struct iperf_test *test)
}
close(s);
}

return 0;
error_handling:
close(s);
return ret;
}


Expand Down

0 comments on commit 8f5a87e

Please sign in to comment.