int main(int argc, char **argv) { rstatus_t status; struct instance nci; nc_set_default_options(&nci); status = nc_get_options(argc, argv, &nci); if (status != NC_OK) { nc_show_usage(); exit(1); } if (show_version) { nc_show_version(); exit(0); } if (show_help) { nc_show_usage(); exit(0); } if (describe_stats) { stats_describe(); exit(0); } if (test_conf) { if (!nc_test_conf(&nci)) { exit(1); } exit(0); } status = nc_pre_run(&nci); if (status != NC_OK) { nc_post_run(&nci); exit(1); } nc_run(&nci); nc_post_run(&nci); exit(1); }
int main(int argc, char **argv) { rstatus_t status; struct instance nci; nc_set_default_options(&nci); status = nc_get_options(argc, argv, &nci); if (status != NC_OK) { nc_show_usage(); exit(1); } if (show_version) { log_stderr("This is nutcracker-%s" CRLF, NC_VERSION_STRING); if (show_help) { nc_show_usage(); } if (describe_stats) { stats_describe(); } exit(0); } if (test_conf) { if (!nc_test_conf(&nci)) { exit(1); } exit(0); } status = nc_pre_run(&nci); if (status != NC_OK) { nc_post_run(&nci); exit(1); } nc_run(&nci); nc_post_run(&nci); exit(1); }
int main(int argc, char **argv) { rstatus_t status; int i, count; //argv [0] = 'master'; if (nc_save_argv(argc, argv) != NC_OK) { exit(1); } nc_set_default_options(&env_global); env_global.worker_processes = sysconf(_SC_NPROCESSORS_ONLN); env_global.cpu_mask = (1<<env_global.worker_processes) - 1; status = nc_get_options(nc_argc, nc_argv, &env_global); if (status != NC_OK) { nc_show_usage(); exit(1); } if (show_version) { log_stderr("This is nutcracker-%s" CRLF, NC_VERSION_STRING); if (show_help) { nc_show_usage(); } if (describe_stats) { stats_describe(); } exit(0); } if (test_conf) { if (!nc_test_conf(&env_global)) { exit(1); } exit(0); } memcpy(&nci_global, &env_global, sizeof(struct instance)); // context will be initialized in later nc_run. if (nc_init_setproctitle() != NC_OK) { exit(1); } status = nc_master_pre_run(&env_global); if (status != NC_OK) { nc_master_post_run(&env_global); exit(1); } count = 0; for(i = 0; i<sysconf(_SC_NPROCESSORS_ONLN); i++) { count+= env_global.cpu_mask & (0x1<<i)?1:0; //log_error("count %d", count); } if (count < env_global.worker_processes) { log_error('cpu mask %x is not fit in worker processes %d', env_global.cpu_mask, env_global.worker_processes); nc_master_post_run(&env_global); exit(1); } /* parse and create configuration for master */ struct conf* cf = malloc(sizeof(struct conf)); memset(cf, 0, sizeof(struct conf)); cf = conf_create(env_global.conf_filename); if (status != NC_OK) { conf_destroy(cf); exit(1); } /* initialize server pool from configuration */ status = tw_master_conf_init(&env_global.pool, &cf->pool); if (status != NC_OK) { conf_destroy(cf); // release array server pool exit(1); } tw_master_cycle(&env_global); nc_master_post_run(&env_global); exit(1); }