BOOL do_run(ui_cmd_t* cmd, app_data_t* app_data) { unsigned i; if (!app_data->loaded) { printf("Must call 'load' before 'run'.\n"); return FALSE; } if (!app_data->initialized) { initialize_threads(app_data); } app_data->policy = atoi(cmd->param); //if param is empty, 0 is returned which is spDefault. app_data->job_count = 0; for (i=0;i<app_data->ntasks; ++i) { app_data->tasks[i].done = FALSE; } threads_start(); printf("All threads terminated.\n"); app_data->initialized = FALSE; return TRUE; }
int main(void) { default_port = DEFAULT_PORT; int listenfd; char *pPort = getenv("PORT"); if (pPort != NULL) default_port = (u_short) strtol(pPort, (char **)NULL, 10); listenfd = open_listenfd(default_port); if (listenfd > 0) { dbgprintf("listen on port %d, fd is %d\n", default_port, listenfd); } else { perror("ERROR"); exit(listenfd); } /*Ignore SIGPIPE signal, so if browser cancels the request, it won't kill the whole process. */ signal(SIGPIPE, SIG_IGN); #ifdef NOPE_THREADS struct rlimit limit; limit.rlim_cur = MAX_NO_FDS * 4; limit.rlim_max = MAX_NO_FDS * 4; setrlimit(RLIMIT_NOFILE, &limit); /* Get max number of files. */ getrlimit(RLIMIT_NOFILE, &limit); dbgprintf("The soft limit is %llu\n", limit.rlim_cur); dbgprintf("The hard limit is %llu\n", limit.rlim_max); initialize_threads(); #endif #ifdef NOPE_PROCESSES for (i = 0; i < NOPE_PROCESSES; i++) { int pid = fork(); if (pid == 0) { // child select_loop(listenfd); } else if (pid > 0) { // parent dbgprintf("child pid is %d\n", pid); } else { perror("fork"); } } #else /* Non-blocking if single processes */ if (FCNTL_NONBLOCK(listenfd) < 0) perror("fcntl"); #endif select_loop(listenfd); return 0; }
BOOL do_load(ui_cmd_t* cmd, app_data_t* app_data) { FILE* file; if (app_data->loaded) { printf("Already loaded.\n"); return FALSE; } file = fopen(cmd->param,"r"); if (file == NULL) { printf("File not found %s\n", cmd->param); return FALSE; } *app_data = load_app_data(file); initialize_threads(app_data); fclose(file); return TRUE; }