Skip to content

Commit

Permalink
Merge branch 'master' into issue-1704-coding-style-consistent-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
penglei0 committed May 27, 2024
2 parents 7245240 + 8f5a87e commit e9ef0ca
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2888,7 +2888,7 @@ iperf_new_test()
i_errno = IENEWTEST;
return NULL;
}
memset(test->bitrate_limit_intervals_traffic_bytes, 0, sizeof(sizeof(iperf_size_t) * MAX_INTERVAL));
memset(test->bitrate_limit_intervals_traffic_bytes, 0, sizeof(iperf_size_t) * MAX_INTERVAL);

/* By default all output goes to stdout */
test->outfile = stdout;
Expand Down
27 changes: 14 additions & 13 deletions src/iperf_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,36 @@
* as Android NDK does not support `pthread_cancel()`.
*/

#include <string.h>
#include <signal.h>
#include "iperf_pthread.h"

int pthread_setcanceltype(int type, int *oldtype) { return 0; }
int pthread_setcancelstate(int state, int *oldstate) { return 0; }
int pthread_cancel(pthread_t thread_id) {
int status;
if ((status = iperf_set_thread_exit_handler()) == 0) {
status = pthread_kill(thread_id, SIGUSR1);
}
return status;
}

void iperf_thread_exit_handler(int sig)
{
{
pthread_exit(0);
}

int iperf_set_thread_exit_handler() {
int rc;
struct sigaction actions;

memset(&actions, 0, sizeof(actions));
memset(&actions, 0, sizeof(actions));
sigemptyset(&actions.sa_mask);
actions.sa_flags = 0;
actions.sa_flags = 0;
actions.sa_handler = iperf_thread_exit_handler;

rc = sigaction(SIGUSR1, &actions, NULL);
return rc;
}

int pthread_setcanceltype(int type, int *oldtype) { return 0; }
int pthread_setcancelstate(int state, int *oldstate) { return 0; }
int pthread_cancel(pthread_t thread_id) {
int status;
if ((status = iperf_set_thread_exit_handler()) == 0) {
status = pthread_kill(thread_id, SIGUSR1);
}
return status;
}

#endif // defined(HAVE_PTHREAD) && defined(__ANDROID__)
4 changes: 2 additions & 2 deletions src/iperf_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
*/

#define PTHREAD_CANCEL_ASYNCHRONOUS 0
#define PTHREAD_CANCEL_ENABLE NULL
#define PTHREAD_CANCEL_ENABLE 0

int pthread_setcanceltype(int type, int *oldtype);
int pthread_setcancelstate(int state, int *oldstate);
int pthread_cancel(pthread_t thread_id);

#endif // defined(__ANDROID__)

#endif // defined(HAVE_PTHREAD)
#endif // defined(HAVE_PTHREAD)
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
4 changes: 2 additions & 2 deletions src/iperf_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ iperf_tcp_accept(struct iperf_test * test)
{
int s;
signed char rbuf = ACCESS_DENIED;
char cookie[COOKIE_SIZE];
char cookie[COOKIE_SIZE] = {0};
socklen_t len;
struct sockaddr_storage addr;

Expand Down Expand Up @@ -149,7 +149,7 @@ iperf_tcp_accept(struct iperf_test * test)
return -1;
}

if (strcmp(test->cookie, cookie) != 0) {
if (strncmp(test->cookie, cookie, COOKIE_SIZE) != 0) {
if (Nwrite(s, (char*) &rbuf, sizeof(rbuf), Ptcp) < 0) {
iperf_err(test, "failed to send access denied from busy server to new connecting client, errno = %d\n", errno);
}
Expand Down

0 comments on commit e9ef0ca

Please sign in to comment.