in src/main.c [312:390]
int main(int argc, char **argv)
{
int err_code = NO_ERROR;
cpu_set_t cpuset;
struct ntttcp_test *test;
struct ntttcp_test_endpoint *tep;
/* catch SIGINT: Ctrl + C */
if (signal(SIGINT, sig_handler) == SIG_ERR)
PRINT_ERR("main: error when setting the disposition of the signal SIGINT");
/*
* Set the SIGPIPE handler to SIG_IGN.
* This will prevent any socket or pipe write from causing a SIGPIPE signal.
*/
signal(SIGPIPE, SIG_IGN);
print_version();
test = new_ntttcp_test();
if (!test) {
PRINT_ERR("main: error when creating new test");
exit(-1);
}
default_ntttcp_test(test);
err_code = parse_arguments(test, argc, argv);
if (err_code != NO_ERROR) {
PRINT_ERR("main: error when parsing args");
print_flags(test);
free(test);
exit(-1);
}
err_code = verify_args(test);
if (err_code != NO_ERROR) {
PRINT_ERR("main: error when verifying the args");
print_flags(test);
free(test);
exit(-1);
}
prepare_logging(test->verbose, test->save_console_log, test->console_log_filename);
if (test->verbose)
print_flags(test);
if (!check_resource_limit(test)) {
PRINT_ERR("main: error when checking resource limits");
free(test);
exit(-1);
}
turn_off_light();
if (test->cpu_affinity != -1) {
CPU_ZERO(&cpuset);
CPU_SET(test->cpu_affinity, &cpuset);
PRINT_INFO("main: set cpu affinity");
if (pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset) != 0)
PRINT_ERR("main: cannot set cpu affinity");
}
if (test->daemon) {
PRINT_INFO("main: run this tool in the background");
if (daemon(0, 0) != 0)
PRINT_ERR("main: cannot run this tool in the background");
}
if (test->client_role == true) {
tep = new_ntttcp_test_endpoint(test, ROLE_SENDER);
err_code = run_ntttcp_sender(tep);
} else {
tep = new_ntttcp_test_endpoint(test, ROLE_RECEIVER);
err_code = run_ntttcp_receiver(tep);
}
free_ntttcp_test_endpoint_and_test(tep);
return err_code;
}